The project: Convert letter-sized PDFs to legal, add the job identifier and folio to the bottom left.

Of course my first thought was - a quick 5 minute perl script! Loaded up PDF::API2, read the docs, and got to coding. Below is the snippet we are concerned about:

#!perl # CLI arguments: # 0 = path to PDF to convert # 1 = job identifier, 5 digit string # 2 = folio start number, no default # include modules use PDF::API2; # declarations use constant mm => 25.4 / 72; use constant in => 1 / 72; use constant pt => 1; # load pdf from passed argument my $pdf = PDF::API2->open($ARGV[0]) || die("Unable to open PDF"); # font definitions my %font = ( Helvetica => { Bold => $pdf->corefont('Helvetica-Bold',-encoding => 'latin1 +' ), Roman => $pdf->corefont('Helvetica',-encoding => 'latin1' ), Italic => $pdf->corefont('Helvetica-Oblique',-encoding => 'lat +in1' ), }, Verdana => { Bold => $pdf->corefont('Verdana-Bold',-encoding => 'latin1' +), Roman => $pdf->corefont('Verdana',-encoding => 'latin1' ), Italic => $pdf->corefont('Verdana-Italic',-encoding => 'latin1 +' ), BoldItalic => $pdf->corefont('Verdana-BoldItalic',-encoding => + 'latin1' ), }, ); # get total number of pages my $pagenumber = $pdf->pages; # folio offset, if we dont want to start at 1 my $offset = int($ARGV[2]-1); for ($count=1; $count<=$pagenumber; $count++) { # get the current page my $page = $pdf->openpage($count); # resize the pdf to legal $page->mediabox('Legal'); $page->cropbox('Legal'); $page->bleedbox('Legal'); $page->trimbox('Legal'); $page->artbox('Legal'); # construct a text box my $text = $page->text; # define font, face, pointsize $text->font( $font{"Verdana"}{"Roman"}, 12/pt ); # font color (not background) $text->fillcolor("#000000"); # x/y coords, remember cartesian coordinates, left,bottom = 0,0 $text->translate( 74/pt, 3/pt ); # actual text to place, text_right is single line look at text_blo +ck for para's $text->text_right($ARGV[1] . "_" . ($count+$offset)); }

The problem: When we change the page dimensions to Legal, all the "space" is added at the top where as we want all the space to be at the bottom. This is to be expected, since I'm guessing it is just adding more to the pages x,y, and 0,0 being the bottom left. Meaning a larger page dimension would increase the page from the top-right and out.

How would one go about tackling this issue? I cannot change the existing pdf before it gets to me, though. Is there some function I'm missing to offset the current contents by the difference of letter and legal (increasing their 'y' so they all move up the page), or do I should I parse the PDF and completely rebuild it?

Thank you for any considerations, or opinions I should take to remedy this.


In reply to PDF::API2 Page Dimensions Layout by dimv

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.