Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

Re: PDF page numbering

by snoopy (Deacon)
on Mar 26, 2009 at 06:48 UTC ( #753355=note: print w/replies, xml ) Need Help??

in reply to PDF page numbering

Here's a possible solution using PDF::API2. This adds a page number centered along the top of the page.

When overprinting on an existing PDF, I tend to convert the input pages to a PDF form using the importPageIntoForm and formimage methods.

#!/usr/bin/perl use warnings; use strict; use PDF::API2; my $infile = shift (@ARGV) or die "usage $0: infile outfile"; my $outfile = shift (@ARGV) || $infile.'paginated'; my $pdf_in = PDF::API2->open($infile); my $pdf_out = PDF::API2->new; foreach my $pagenum (1 .. $pdf_in->pages) { my $page_in = $pdf_in->openpage($pagenum); # # create new page # my $page_out = $pdf_out->page(0); # # Get the page size # my @mbox = $page_in->get_mediabox; # # Inherit mediabox $page_out->mediabox(@mbox); # # copy page as a form. # my $gfx = $page_out->gfx; my $xo = $pdf_out->importPageIntoForm($pdf_in, $pagenum); $gfx->formimage($xo, 0, 0, # x y 1); # scale my $left_edge = $mbox[0]; my $right_edge = $mbox[2]; my $top = $mbox[3]; my $txt = $page_out->text; $txt->strokecolor('#000000'); $txt->fillcolor('#000000'); $txt->translate(my $_x = ($right_edge - $left_edge) / 2 - 10, my $_y = $top - 15 ); my $font = $pdf_out->corefont('Courier'); $txt->font($font, 12); $txt->text( 'Page: '.$pagenum ); } $pdf_out->saveas($outfile);

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://753355]
[erix]: choroba I believe you ;)
[1nickt]: Corion I assume you are talking about Retry? Attempt doesn;t offer callbacks and has a much simpler interface. (Also written by someone I trust...)
[perldigious]: I train for long portaging/rowing trips by carrying my kayak to the river about a half mile from my house 2-3 times a week depending on weather... but due to a lingering winter, I haven't had long to train this year.

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (10)
As of 2017-05-24 12:58 GMT
Find Nodes?
    Voting Booth?