Perl Pdf Api2
I used to set my PDF::API2 fonts like this in my Perl script, it worked fine:
Then when I wanted to print unicode characters (Russian Cyrillic characters) it did not work. I found out, that you have to use TrueType fonts and then all these special characters would work. So I tried this:
Perl API2 Font Examples Embedding TrueType Fonts. Finding examples of working with TrueType Fonts in API2 is like pulling teeth. I know I lost a few trying to get the thing to work. Turns out, embedding a TTF into a PDF isn't that difficult. This isn't a tutorial, but it should help some of you out there! PDF-API2 (0.55) If you want to produce PDFs, and have to use Perl, use this module. Sine it's initial release, I have found it to be easy to use to produce simple documents, over every aspect of my PDF creation, from image contact sheets, to relatively complex tabulated data.
- PDF::API2 will aim to support all major Perl versions that were released in the past six years, plus one, in order to continue working for the life of most long-term-stable (LTS) server distributions.
- As a valued partner and proud supporter of MetaCPAN, StickerYou is happy to offer a 10% discount on all Custom Stickers, Business Labels, Roll Labels, Vinyl Lettering or Custom Decals. StickerYou.com is your one-stop shop to make your business stick. Use code METACPAN10 at checkout to apply your discount.
Before I copied the file 'times.ttf' from my Windows font directory to any directory where PDF::API2 could be looking: The directory where my script is located, the directory where PDF::API2 is located, and several other directories. But I always got an 'Internal Server Error' message. The script runs on a Linux server. I also tried that:
(I created 'external_ttfs' before as a sub directory of PDF::API2's 'PDF' directory. It did not work either. I thought maybe the problem could be the 'times.ttf' file, it might not have the correct format. So I downloaded 'DejaVuSans.ttf', a free font. I copied also this file to various directories of my webspace. But also this command caused the internal server error:
Does anybody have an idea what could be the problem? Thank you in advance! I don't have a clue if the TTF file is not correct, if it cannot be found, or if there is any other problem.
2 Answers
vsinghvsinghDo you install the Font:TTF module on Perl?Download it from here and add it to Perl lib folder then retry.
Perl Cpan Pdf Api2
Not the answer you're looking for? Browse other questions tagged pdf-generationtrue-type-fonts or ask your own question.
Below is complete minimal code required to create a single PDF file using Perl module PDF::API2. The first PDF is created fine. At the start of the attempt to create the second PDF, the process fails at the second instance of line:
with the error, Can't call method 'new_obj' on an undefined value at C:/Perl64/site/lib/PDF/API2/Basic/PDF/Pages.pm line 92.
Yu gi oh gx full episodes. Why? More importantly, what change do I have to make to create a second pdf?
2 Answers
Using Data::Dumper
after first creating $pdf
reveals a lot of data:
This is all removed after the call to saveas
, causing the undefined value
error:
You could recreate $pdf
:
but then you'd also need to add all the other method calls (corefonts
, mediabox
, text
). Easier to put the PDF creation code into a sub:
Then call it twice with relevant arguments.
Full working example:
RobEarlRobEarl