I believe the core fonts (i.e. what you get via $pdf->corefont(...) ) simply don't work with Unicode (investigation of the sources and extensive playing around essentially confirmed my suspicion that the generated font descriptions are always classical "Type 1" with an 8-bit encoding vector).  I'd be happy to be proven wrong, though!

OTOH, when you use an appropriate TTF font which has the required glyphs, things work just fine:

#!/usr/bin/perl use strict; use warnings; use PDF::API2; # Create a blank PDF file my $pdf = PDF::API2->new(); # Add a blank page my $page = $pdf->page(); my $font = $pdf->ttfont('DejaVuSans.ttf'); my $ustring = "\x{03a7}\x{03b1}\x{03b9}\x{03c1}\x{03b5}!"; # Add some text to the page my $text = $page->text(); $text->font($font, 20); $text->translate(80, 710); $text->text($ustring); # Save the PDF $pdf->saveas('test.pdf');

DejaVu is a free font with very good Unicode coverage (see the unicover.txt file that comes with the package for details).  And if you feel like designing your own glyphs, you can even download the font's FontForge source files...

P.S.: older versions of PDF::API2 (up to the maintainer change with 2.016) shipped with the DejaVu fonts included, so you may already have them under PDF/API2/fonts/.   Otherwise, if you install them somewhere else, you might want to specify the full path to the respective .ttf file.


In reply to Re^2: PDF::API2 / unicode characters by Eliya
in thread PDF::API2 / unicode characters by PerlSci

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.