#!/usr/bin/perl if($#ARGV ne 1){ print "TO update to a single xref table (unix format)\n"; print "USAGE: uppdf.pl infile.pdf outfile.pdf\n"; }else{ $infile = $ARGV[0]; $outfile = $ARGV[1]; # open(Lista,"<$infile")||die "Can't open the file"; open(OUT,">$outfile")||die "Can't open the file"; # ################################## # # This is the program that does all the counting # if you hack a PDF in a text editor: remove a page, swap # pages, change a bounding box, run this program # update the xref table and the startxref address at the # end. If there is more than one xref, this program might # fail without warning, however, it attempts to construct # a single xref table out of multiple tables. # @listind = ; # $numberobj = 0; $size = 0; # # the BYTE COUNT starts at one and marks the \n before the obj at hand # $count = 0; $tail = 0; $body = 1; # # select(OUT); for $i (@listind){ # # encountered xref, which is the blur we ignore # if($i =~ /xref/){ $body = 0; $xrefaddress = $count; } if($body eq 1){ # # for every object we store the byte address and the # generation number to write in the xref table at the end. # if($i =~ /(\d+)\s+(\d+)\s+obj/i){ $objnumber = $1; @objgen[$objnumber-1] = $2; if($numberobj < $objnumber){ $numberobj = $objnumber; } @objaddress[$objnumber-1] = $count; } $count += length($i); print $i; }else{ # # we store trailer info in the string $trailer. Some # info is double (Size, ID, >>), some info is superfluous (Prev). # if($i =~ /trailer/){ $tail = 1; } # # startxref signals the end of the trailer # if($i =~ /startxref/){ $tail = 0; } # if($tail eq 1){ $i =~ s/trailer//; $i =~ s/>>//; $i =~ s/<\>\n"; print "startxref\n"; print $xrefaddress."\n"; print "%%EOF\n"; close(Lista); close(OUT); }