|
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 |