| 1 | #! /usr/bin/perl -w |
| 2 | |
| 3 | # Program to add page label information to the PDF output file. I have not |
| 4 | # found a way of automatically discovering the number of frontmatter pages |
| 5 | # in the document. It is therefore taken as an argument to be inserted into the |
| 6 | # next statement. |
| 7 | |
| 8 | $add = "/PageLabels << /Nums [ 0 << /S /r >>\n" . |
| 9 | " $ARGV[0] << /S /D >>\n" . |
| 10 | " ]\n" . |
| 11 | " >>\n"; |
| 12 | |
| 13 | $extra = length $add; |
| 14 | |
| 15 | $before = 0; |
| 16 | while (<STDIN>) |
| 17 | { |
| 18 | print; |
| 19 | $before += length($_); |
| 20 | last if $_ =~ "^<< /Type /Catalog"; |
| 21 | } |
| 22 | |
| 23 | print $add; |
| 24 | |
| 25 | while (<STDIN>) |
| 26 | { |
| 27 | print; |
| 28 | last if $_ =~ /^xref$/; |
| 29 | } |
| 30 | |
| 31 | while (<STDIN>) |
| 32 | { |
| 33 | if (/^(\d{10}) (.*)/) |
| 34 | { |
| 35 | my($was) = $1; |
| 36 | my($rest) = $2; |
| 37 | printf "%010d $rest\n", $was + (($was > $before)? $extra : 0); |
| 38 | } |
| 39 | elsif (/^startxref/) |
| 40 | { |
| 41 | print; |
| 42 | $_ = <STDIN>; |
| 43 | if (/^(\d+)/) |
| 44 | { |
| 45 | print $1 + $extra, "\n"; |
| 46 | } |
| 47 | else |
| 48 | { |
| 49 | print; |
| 50 | } |
| 51 | } |
| 52 | else |
| 53 | { |
| 54 | print; |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | # End |
| 59 | |
| 60 | |