in reply to PDF suggestions ?

my $utftext=qq(SOme UTF text); #$utftext=encode("utf8", decode("cp1251", $utftext) ) ; #$utftext=encode("utf8", $utftext ) ; my $pdf; $pdf = PDF::API2->open('first.pdf'); my $page_number = 1; my $page = $pdf->openpage($page_number); my $font = $pdf->corefont('Verdana');# ,-encoding => 'utf8' my $text = $page->text(); $text->font($font, 30); $text->translate(359, 713); $text->text("$utftext"); $pdf->saveas('mysaved.pdf');

Replies are listed 'Best First'.
Re^2: PDF suggestions ?
by Eliya (Vicar) on Mar 16, 2012 at 15:04 UTC

    (I'm supposing you're the same AM as in the OP)

    Don't use the corefonts, use ttfont() instead and specify the path to the respective .ttf file directly  (a subset of the font, i.e. the required glyphs, will automatically be embedded into the PDF):

    my $font = $pdf->ttfont('/path/to/verdana.ttf');

    See also Re^2: PDF::API2 / unicode characters.

    (And do not encode("utf8", $utftext) the string yourself... — leave it decoded, so Perl can handle Unicode characters correctly.)

      I got the following error: Use of uninitialized value in pack at C:/Perl/site/lib/Font/TTF/Cmap.pm line 329. Any ideas how to solve the problem ?
      my $utftext=qq(SOme UTF text); #$utftext=encode("utf8", decode("cp1251", $utftext) ) ; #$utftext=encode("utf8", $utftext ) ; my $pdf; $pdf = PDF::API2->open('first.pdf'); my $page_number = 1; my $page = $pdf->openpage($page_number); #my $font = $pdf->corefont('Verdana');# ,-encoding => 'utf8' my $font = $pdf->ttfont('mypath/times.ttf'); my $text = $page->text(); $text->font($font, 30); $text->translate(359, 713); $text->text("$utftext"); $pdf->saveas('new.pdf');