I wanted to build an awesome place for people to discuss module specific issues, but I don't have any more time for this, and there are much better places to discuss Perl-related issues. I'd recommend asking your question on Stack Overflow or on Perl Monks.
If you are looking for a Perl tutorial or Perl-related news, I hope these links will serve you well.
Posted on 2009-02-09 08:22:44-08 by andhan in response to 9897
Re: example PDF with embedded TTF and Unicode encoding?
Hi Torsten
Normally you will not find a font that contains every character you need, so I rather use the unifont to merge several font when I want to create "utf-8" documents.
Here is an example of a document combining the PDF build-in font with a Thai-font you can find on the net and download.
PDF::API2 often produces a lot of warnings with ttf-fonts, so I use the "$^W = 0" to disable warnings. Probably there is a better way to do this.

code test.pl:
#!/usr/bin/perl -w use PDF::API2(); use strict(); use constant mm => 25.4 / 72; # Create the Document my $pdf = PDF::API2->new(); my $page = $pdf->page; my %papersizes = PDF::API2::Util::getPaperSizes(); $page->mediabox ($papersizes{'a4'}); $page->cropbox ($papersizes{'a4'}); # Create a unifont containing built-in Roman font, and Loma for thai characters $^W = 0; my $Roman = $pdf->corefont( 'Times', -encode=>'unicode'); my $RomanThai = $pdf->ttfont('Loma.ttf', -encode=>'unicode'); # 0x0E00--0x0EFF my $uftRoman = $pdf->unifont($Roman, [$RomanThai, 0x0E], -encode=>'unicode'); # Set up txt object $txt = $page->text; $txt->font($uftRoman, 28); $txt->translate(20/mm, 260/mm); $txt->lead(32); # Write some english: $txt->text("English: Hello"); $txt->nl(); # Write some Thai: $txt->text("Thai: \x{e2a}\x{e27}\x{e31}\x{e2a}\x{e14}"); $txt->nl(); # Save the document $pdf->saveas('Thai-test.pdf');

Regards, Andreas
Direct Responses: Write a response