Hello Andrea,

I am fairly a newb at using PDF::API2 -- I took a crack at trying to figure it out a few weeks ago, but decided it was more trouble than it was worth for what I needed -- but I saw your lonely post, and felt inclined to offer what help I could, being a lover of Unicode and Greek characters especially.

To your questions:

-- According to the PDF::API2::Resource::Font::CoreFont manpage, the core fonts they list (Times Roman, Verdana, etc.) *ought* to support UTF8, and the standard Greek characters.

-- According to the PDF::API2 manpage, you should be able to import standard TrueType fonts.

-- PDF::API seems to be the best interface for PDF that I've found. But I am, as I said, a newb.

I just followed what appeared to be the procedure for assigning a Unicode font with PDF/API2/Resource/UniFont.pm. But it doesn't seem to be working. I can why you are frustrated! I need to get to class, but my interest is now piqued, and I'll try to work more on this later today. For what it's worth, and for anyone else who comes along to help, here's what I'm working with:

#/usr/bin/perl use strict; use warnings 'all'; use PDF::API2; use PDF::API2::Resource::UniFont my $test = 'test.pdf'; # Create a blank PDF file my $pdf = PDF::API2->new(); # Add a blank page my $page = $pdf->page(); # Add a built-in font to the PDF my $font = $pdf->corefont('Times-Roman'); # Register a Unicode font my $ufont = PDF::API2::Resource::UniFont->new($pdf, {font => $font}); # Create a Unicode string (Greek) my @uhex = qw(03a7 03b1 03b9 03c1 03b5 0021); my @uchars = map (hex, @uhex); my $ustring = pack("U*", @uchars); # Add some text to the page my $text = $page->text(); $text->font($ufont, 20); $text->translate(80, 710); $text->text($ustring); # Save the PDF $pdf->saveas('test.pdf');

All it puts on the page, presently, is the ASCII, non-Unicode exclamation point.

In reply to Re: PDF::API2 / unicode characters by LonelyPilgrim
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.