Debian Codegraph @

scripts/pdfrevert

raw ◀ ▶
1 Debian patch touch this file
1 #!/usr/bin/perl
2
•3 =head1 NAME
4
5 pdfrevert.plx - Removes one layer of edits from a PDF file
6
7 =head1 DESCRIPTION
8
9 Removes one layer of changes to a PDF file, trying to maximise the
10 size of the output file (to account for linearised PDF).
11
12 =head1 SYNOPSIS
13
14 PDFREVERT infile
15
16 =cut
17
18 use Text::PDF::File;
19
20 unless (defined $ARGV[0])
21 {
22 die <<'EOT';
23 PDFREVERT infile
24
25 Removes one layer of changes to a PDF file, trying to maximise the size of the
26 output file (to account for linearised PDF).
27 EOT
28 }
29
30 $cr = '\s*(?:\r|\n|(?:\r\n))';
31 $VERSION = "1.000"; # MJPH 6-NOV-1998 Original
32
33 $f = Text::PDF::File->open($ARGV[0], 1);
34 exit unless defined $f->{'Prev'};
35
36 # account for linearised pdf, maximise output
37 for ($t = $f; defined $t->{' prev'}; $t = $t->{' prev'})
38 {
39 $loc1 = $t->{'Prev'}->val;
40 $loc = $loc1 if ($loc1 > $loc);
41 }
42
43 $fd = $f->{' INFILE'};
44 seek($fd, $loc, 0);
45 $rest = "";
46 while ($len = read($fd, $dat, 1024))
47 {
48 $len += length($rest);
49 $_ = $rest . $dat;
50 if (m/(?:\r|\n|(?:\r\n))%%EOF$cr/oi)
51 {
52 $loc += length($` . $&);
53 last;
54 }
55 elsif (m/$cr(.*?)$/oi)
56 {
57 $rest = $1;
58 $loc += $len - length($rest);
59 }
60 }
61
62 if ($len != 0)
63 {
64 truncate($fd, $loc) || die "Can't truncate";
65 }
66