Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
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.

Replies are listed 'Best First'.
Re^2: PDF::API2 Page Dimensions Layout
by dimv (Novice) 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?
[stevieb]: it's Quebec... they do weird stuff there :) In the mountains, it is *mandatory* for trucks to use tire chains. Many passenger vehicles do as well (but it's not mandatory for them)
[perldigious]: That stuff can hit fast... like what we just got where I'm at. Saw a few people who had slid OUT of the roundabout I have to drive through to get to work, not used to the ice yet, take awhile to get the hang of it again and make vehicle adjustments.
[stevieb]: man, when the roads are glare ice, I don't even bother going to work or out... unless I absolutely have to, or was already out in the first place
[choroba]: Tire chains are mandatory here in mountains, and the only unprepared each year are gritters
[stevieb]: I have a 3 day winter survival kit in my vehicle in the event I get snowed in in the mountains (which has happened before due to avalanches closing the roads (and once in the summer due to a massive forest fire that trapped us
[perldigious]: a handful of people in my work area did not make it, but I live pretty close and it's flat the whole way, so I didn't have any trouble. The roundabout is the worst thing I have to negotiate.
[thezip]: G'day all!
[perldigious]: Well, that and dodging the people who forget how ice works right away. :-)
[stevieb]: hey, thezip
[perldigious]: I don't miss having to drive up and down in elevation on roads that are iced over, I white knuckled gripping the steering wheel every time I had to where I used to live.

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (10)
As of 2016-12-06 16:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:













    Results (112 votes). Check out past polls.