ssimms / pdfapi2

Create, modify, and examine PDF files in Perl
Other
15 stars 20 forks source link

Problem loading an emoji font #47

Open book opened 2 years ago

book commented 2 years ago

Hi,

I was trying to put some emoji characters in a PDF, and started by trying to load an emoji font.

use strict;
use warnings;
use PDF::API2;

my $pdf  = PDF::API2->new();
my $page = $pdf->page();
my $text = $page->text();

# the font was downloaded from
# https://github.com/googlefonts/noto-emoji/raw/main/fonts/NotoColorEmoji.ttf
my $font = $pdf->font('NotoColorEmoji.ttf');

$text->font( $font, 24 );
$text->position( 72, 720 );
$text->text('Hello world');

$pdf->save('sample.pdf');

The script fails while loading the font:

Can't call method "read" on an undefined value at /usr/share/perl5/PDF/API2/Resource/CIDFont/TrueType/FontFile.pm line 556.

I expect putting some Unicode Emoji character in a PDF file is bit more complicated than doing $text->text("♥") with the appropriate font. This is failing when loading the font, however.

Regards,