My application receives a PDF that the user uploads, then I use PDF::API2 to open the file, print a few words in 10 point font at the top left corner of the first page of the PDF, then save it to a folder. Pretty simple.
I figured out how to do this by trial and error, and it has worked fine for months, but I recently found a problem. A user uploaded a PDF and the text was printed on the first page but instead of the top left corner in 10 point font, it was printed in the middle of the page in tiny microscopic font.
What was different about this PDF? Well it was PDF Version 1.3, which is pretty old, so I thought maybe that was the problem. But then I tested a different 1.3 PDF and it worked fine.*
*It worked fine only when I commented out the code in the API2 module that checks PDF version and actually returns an error when I try to work with a PDF of version 1.3. I have no idea why this code doesn't give an error when I upload the original, problematic 1.3 PDF. I am leaving this code commented out because I really need to be able to process older PDFs if possible.
In summary, I have no idea why my code is putting my text in the wrong place and at the wrong size for this one document that happens to be PDF Version 1.3 (Don't know if that is even relevant). Here is my ugly code that may be fraught with errors, please help!
my $file = shift; #receive input file as param
my $pdf = PDF::API2->open($file);
my $page = $pdf->openpage(1); #open the first page
my $font = $pdf->corefont('Helvetica-Bold');
my $text = $page->text();
$text->font($font,10); #10-point font size
$text->translate(15,770); #top left corner.. 0,0 origin starts in the
+bottom left corner
$text->text('blah blah sample text');