Thanks to a tip from Friar snoopy, I have a working Bates Number script. I got some interesting results when I ran this on the PDF specs at adobe.com. I'll post that next.
#!/usr/local/bin/perl $| = 1; # flush output use warnings; use strict; use PDF::API2; use POSIX qw(floor); use Smart::Comments; my $diemsg = setDieMsg(); my $batesStartStr = shift (@ARGV); die $diemsg.'(batesStartStr)' if !d +efined $batesStartStr; my $batesEndStr = shift (@ARGV) ; die $diemsg.'(batesEndStr)' if !defi +ned $batesEndStr; my $batesNum = shift (@ARGV) ; die $diemsg.'(batesNum)' if !defined $b +atesNum; my $scale = shift (@ARGV) ; die $diemsg.'(scale)' if !defined $scale; my $adjust = shift (@ARGV) ; die $diemsg.'(adjust)' if !defined $adjus +t; my $infile = shift (@ARGV) or die $diemsg.'(infile)'; my $outfile = shift (@ARGV) || $infile.'bates.pdf'; my $pdf_in = PDF::API2->open($infile) or die "can't PDF::API2->open($infile): $!"; my $pdf_out = PDF::API2->new(-file => $outfile); ; my $pageCnt = $pdf_in->pages; print "PDF Document $infile $pageCnt pages are now read into memory!\n +" if $pageCnt >100; # some globals my (@mbox, $left_edge, $bottom, $right_edge, $top, $new_left, $new_bot +tom); my ($page_out, $page_in, $gfx, $xo, $txt, $font, $bates); foreach my $pagenum (1 .. $pdf_in->pages) { ### Writing===[%] done # # create new page # $page_out = $pdf_out->page(0); { $page_in = $pdf_in->openpage($pagenum); # # Get the page size # @mbox = $page_in->get_mediabox; # # Inherit mediabox $page_out->mediabox(@mbox); ($left_edge, $bottom, $right_edge, $top) = @mbox; # # copy page as a form. # $gfx = $page_out->gfx; $xo = $pdf_out->importPageIntoForm($pdf_in, $pagenum); # move the scaled down image up to make room for Bates number at b +ottom $new_left = 0; $new_bottom = floor ((1 + $top - $bottom) * (1-$scale)); $gfx->formimage($xo, $new_left, $new_bottom, # x y $scale); # scale $txt = $page_out->text; $txt->strokecolor('#000000'); $txt->fillcolor('#000000'); # print Bates string at bottom of new page, just left of center $txt->translate(my $_x = ($right_edge - $left_edge) / 2 - 10, my $_y = $adjust ); $font = $pdf_out->corefont('Courier'); $txt->font($font, 12); $bates = $batesStartStr.$batesNum++.$batesEndStr; $txt->text( $bates.$pagenum ); # flush the page to save memory on big PDFs $pdf_out->finishobjects($page_out, $gfx, $txt); } } # finish up and exit $pdf_out->save; exit; sub setDieMsg { return <<"DIE"; usage $0: batesStartStr batesEndStr batesNum scale adjust infile <outf +ile> ex: $0 'Kramer v. Kramer-' '-NY2009' 42 .95 old.pdf new.pdf would Bates stamp the first page of old.pdf w/ the string "Kramer v. + Kramer-42-NY2009, increment the page number on next page(s), and output all of the pag +es to new.pdf DIE }
mike

In reply to Re^2: Bates Number in PDF by emike
in thread Bates Number in PDF by emike

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.