I'm using CAM::PDF
to merge several PDF files. This works fine. Now I need to add a stamp on each page using PDF::API2
. This works fine for some pages, but not for others.
PDF files created with wkhtmltopdf seem to have their coordination system flipped and the scaling is off as well.
When running through the pages I add a stamp like this:
my $pdf2 = PDF::API2->open_scalar($pdf_data);
my $page_count = $pdf2->pages;
for my $i ( 1 .. $page_count ) {
my $page = $pdf2->openpage($i);
my $content = $page->gfx();
my $text = $page->text();
$content->linewidth(2);
$content->rectxy( 5, 10, 140, 40 );
$content->stroke;
my $font = $pdf2->ttfont('calibri.ttf');
$text->scale( 1.0, 1.0 );
$text->font( $font, 12 );
$text->translate( 10, 14 );
$text->text( sprintf( 'PAGINA %d VAN %d', $i, $page_count ) );
$text->translate( 10, 26 );
$text->text('some ID');
}
my $pdf_data = $pdf2->stringify;
Now, the pages that are from the wkhtmltopdf have a tiny box with even tinier text in the top left corner (but inside the page margins) and it's mirrored. The non-wkhtmltopdf page has a properly sized box with properly sized text in the bottom left corner (ignoring page margins).
Using $content->scale
and $content->rotate(180)
I can properly display the stamp on the pages created by wkhtmltopdf. But then the other pages are messed up.
So, is there any way to make sure that each document has the same orientation, rotation and scale on all pages?
CAM::PDF
and just pass a single PDF document generated by wkhtmltopdf straight toPDF::API2
the same problem occurs. – Htbaa