Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

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]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (3)
As of 2018-02-24 00:36 GMT
Find Nodes?
    Voting Booth?
    When it is dark outside I am happiest to see ...

    Results (310 votes). Check out past polls.