Hello Monks,
I am trying to generate a pdf report with images using Perl. I am able to write text to the pdf file but I am getting error when trying to write images. Is anything wrong with my code? I am in Linux environment.
my $pdf = PDF::API2->new(); $pdf->mediabox(595,842); my $page = $pdf->page; my $fnt = $pdf->corefont('Arial',-encode => 'latin1'); my $txt = $page->text; $txt->textstart; $txt->font($fnt, 20); $txt->translate(150,800); $txt->text("Dige Images for Experiment"); my $photo = $page->gfx; my $jpeg = $pdf->image_jpeg("http://docs.gimp.org/images/filters/exam +ples/color-taj-sample-colorize.jpg"); $photo->image($jpeg,100,50,60,400); $txt->textend; $pdf->saveas("/tmp/HelloWorldDige24.pdf"); $pdf->end( );
The ERROR is:
error: Can't call method "val" on an undefined value at /usr/lib +/perl5/site_perl/5.8.0/PDF/API2/Resource/XObject/Image.pm line 99. context: ... 95: sub width { 96: my $self = shift @_; 97: my $x=shift @_; 98: $self->{Width}=PDFNum($x) if(defined $x); 99: return($self->{Width}->val); 100: } 101: 102: =item $ht = $img->height 103: ... code stack: /usr/lib/perl5/site_perl/5.8.0/PDF/API2/Resource/XObj +ect/Image.pm:99 /usr/lib/perl5/site_perl/5.8.0/PDF/API2/Resource/XObject/Image/JPEG.pm +:147 /usr/lib/perl5/site_perl/5.8.0/PDF/API2/Resource/XObject/Image/JPEG.pm +:81 /usr/lib/perl5/site_perl/5.8.0/PDF/API2/Resource/XObject/Image/JPEG.pm +:116 /usr/lib/perl5/site_perl/5.8.0/PDF/API2.pm:1898 /usr/local/apache/html/bioinfo/pfc/view/view_digegel.mhtml:86 /usr/local/apache/html/bioinfo/pfc/view/autohandler:107 /usr/local/apache/html/bioinfo/pfc/view/syshandler:42

In reply to Can't call method "val" on an undefined value at /usr/lib/perl5/site_perl/5.8.0/PDF/API2/Resource/XObject/Image.pm line 99 by nargis

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.