#!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
|