in reply to Re^3: External font with PDF::API2::Simple
in thread External font with PDF::API2::Simple

Hi zentara
Thanks for the reply.
I have studied the perl doc extensively but have not been able to work it out.

I missed that but as per your notes and their example, I have added a font size but still get the same error:

my $font_obj = $pdf->pdf->ttfont('freemono.ttf'); $pdf->add_font('MonoFont',$font_obj,12); Can't call method "text" without a package or object reference at /usr +/share/perl5/PDF/API2/Simple.pm line 435.
The subroutine in Simple.pm that has line 435 is:
sub add_font { my ($self, $font_name, $font_obj, $font_size) = @_; if ( $font_obj ) { LINE 435 --> $self->current_page->text->font($font_obj, $font_size); $self->fonts->{$font_name} = $font_obj; } if ( ! exists $self->fonts->{$font_name} ) { $self->fonts->{$font_name} = $self->pdf->corefont($font_name); } $self->current_font( $self->fonts->{$font_name} ); }
I have been unable to see where I'm going wrong.
I presume that what PDF::API2::Simple sends to PDF::API2 is already coded within PDF::API2::Simple, so I figured their example should be all that is needed for it to work?

Would you have any other suggestions that would help track it down or do you think I am missimg something with the above?
I would appreciate any help you could offer with this very frustrating problem.

Replies are listed 'Best First'.
Re^5: External font with PDF::API2::Simple
by zentara (Cardinal) on Sep 21, 2011 at 14:12 UTC
    Why not go back to PDF::API2 ? because the simple has left PDF::API2::Simple. :-)

    This works for me with a generic ttf font

    #!/usr/bin/perl use strict; use warnings; use PDF::API2; my $text = "Some text "; my $pdf = PDF::API2->new(); my $page = $pdf->page; my $txt = $page->text; #my $font = $pdf->corefont('Helvetica-Bold', -encoding => 'latin1'); # alternatively, use TrueType fonts: # my $font = $pdf->ttfont('Verdana-Bold.ttf', -encoding => 'latin1'); my $font = $pdf->ttfont('./Generic.ttf', -encoding => 'latin1'); $txt->font($font, 25); $txt->translate(200, 550); $txt->fillcolor('black'); $txt->text($text); $pdf->saveas("$0.pdf");

    I'm not really a human, but I play one on earth.
    Old Perl Programmer Haiku ................... flash japh
      Simple sure has left home :-)
      Is there a way I could use the PDF::API2 code you show within a program that is otherwise using PDF::API2::Simple?
      Or would I have to convert all of my code to PDF::API2?
        Is there a way I could use the PDF::API2 code you show within a program that is otherwise using PDF::API2::Simple?

        I tried a few examples, but no success. I would go back to straight PDF::API2 myself. Have you tried contact the author of PDF::API2::Simple?


        I'm not really a human, but I play one on earth.
        Old Perl Programmer Haiku ................... flash japh