简体   繁体   中英

Perl PDF::API2 displays boxes for plain ASCII letters

I'm trying to print some text as a simple PDF file. I used the following code, and I got a PDF file, but each letter shows as a box. For example five boxes shown for "Hello", and six boxes for "Hello1". I searched and found this kind of problem usually comes with UTF-8 characters, but mine uses just plain ASCII letters.

use PDF::API2;

my $pdf = PDF::API2->new(); # create a blank pdf file            

my $page = $pdf->page(); # add a blank page                        
$page->mediabox('Letter'); # set page size

my $font = $pdf->corefont('Times'); # set up font

my $ttfPath = 'path/font/fontawesome-webfont.ttf';
$font       = $pdf->ttfont($ttfPath);

my $text = $page->text(); # add text to page                                                                                                                          
$text->font($font, 20);
$text->translate(200, 700);

$text->text("Hello");

$pdf->saveas("test.pdf");

There is no such font as Times . Use Times-Roman .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM