Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: PDF::API2 Page Dimensions Layout

by snoopy (Deacon)
on Aug 16, 2010 at 02:56 UTC ( #855188=note: print w/ replies, xml ) Need Help??


in reply to PDF::API2 Page Dimensions Layout

Maybe, you could take a similar approach to Re: PDF page numbering?

This involves rebuilding each of the pages and overlaying the original page using the importPageIntoForm method.


Comment on Re: PDF::API2 Page Dimensions Layout
Download Code
Re^2: PDF::API2 Page Dimensions Layout
by dimv (Initiate) on Aug 16, 2010 at 04:21 UTC

    That worked beautifully! Thank you so much! Here is the final code in case anyone is interested:

    #!perl # Command Line Arguments:: # 0 = path to original pdf # 1 = job identifier # 2 = folio start - must pass 1 # 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"); # new pdf to hold legal size my $pdf_out = PDF::API2->new; # font definition my %font = ( Verdana => { Bold => $pdf_out->corefont('Verdana-Bold',-encoding => 'lati +n1' ), Roman => $pdf_out->corefont('Verdana',-encoding => 'latin1' ) +, Italic => $pdf_out->corefont('Verdana-Italic',-encoding => 'la +tin1' ) } ); # get total number of pages my $pagenumber = $pdf->pages; # folio offset my $offset = int($ARGV[2]-1); for ($count=1; $count<=$pagenumber; $count++) { # get the current page/new page my $page = $pdf->openpage($count); my $page_out = $pdf_out->page(0); # resize new pdf page to legal $page_out->mediabox('Legal'); $page_out->cropbox('Legal'); $page_out->bleedbox('Legal'); $page_out->trimbox('Legal'); $page_out->artbox('Legal'); # turn old pdf into graphic # import into new pdf at offset my $gfx = $page_out->gfx; my $xo = $pdf_out->importPageIntoForm($pdf, $count); # 612x1008 = legal # 612x792 = letter # y diff is 216 $gfx->formimage($xo, 0, 216, # x y 1); # scale # add our folio identifier # construct a text box my $text = $page_out->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 # for a 8.5x11 doc, the bottom left viewable (not in bleed/crop ar +ea) is approx 68,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)); } # save and close $pdf_out->saveas("C:\\dp\\perlTest.pdf"); $pdf_out->end(); exit

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://855188]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (18)
As of 2015-07-06 14:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (75 votes), past polls