Rather than doing a full import, the following creates a blank page then overlays text and graphics from the source page:
#!/usr/bin/perl use warnings; use strict; use PDF::API2; sub importPageGraphics { my ($pdf,$sourcepdf,$sourceindex,$targetindex) = @_; $sourceindex ||= 1; $targetindex ||= 0; # create new page my $sourcepage = $sourcepdf->openpage($sourceindex); my $targetpage = $pdf->page($targetindex); $targetpage->mediabox($sourcepage->get_trimbox); my $gfx = $targetpage->gfx; my $xoform = $pdf->importPageIntoForm($sourcepdf, $sourceindex); $gfx->formimage($xoform, 0, 0, 1.0); } my $pdf = PDF::API2->new(); my $src_pdf = PDF::API2->open('/tmp/overlay.pdf'); importPageGraphics($pdf,$src_pdf); $pdf->saveas('/tmp/test.pdf');
I found importPageIntoForm and friends to be more reliable and lightweight than the importpage method.
In reply to Re: PDF::API2 importpage
by snoopy
in thread PDF::API2 importpage
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |