clanrbr has asked for the wisdom of the Perl Monks concerning the following question:

Hello monks, So i have the following problem I've oppened a pdf file and want to write QRCODE in it , but the thing is that it should be without saving picture on the hard drive.
my $pdf=PDF::API2->open("$data/$pdfsource"); y $page = $pdf->openpage('1'); my $gfx=$page->gfx();
I've used Imager::QRCode
my $qrcode = Imager::QRCode->new( size => 8, margin => 1, version => 1, level => 'M', casesensitive => 1, lightcolor => Imager::Color->new(255, 255, 255), darkcolor => Imager::Color->new(0, 0, 0), ); my $img = $qrcode->plot("$mylink"); $img->write(data => \$result, type => 'png') or die 'Cannot save \'png\': ', $img->errstr;
And i want to write in the pdf without saving in on the hard so i've tried something like this :
my $png1 = $pdf->image_png($result); $gfx->image($png1 ,590,140,7); my $png2 = $pdf->image_png($img); $gfx->image($png2 ,590,140,7);
I think it doesn't recognize it as picture and can't read the metadata. The following error is an't call method "val" on an undefined value at /usr/local/lib/perl5/site_perl/5.8.9/PDF/API2/Resource/XObject/Image.pm line 66 Thank you and waiting for ideas. Best regards.

Replies are listed 'Best First'.
Re: PDF::API2 and Imager
by zentara (Cardinal) on Aug 29, 2012 at 16:30 UTC
    When you write to $result to make the in-memory png, are you sure it is valid? Can you also write it to a file, and check it?

    Also, the docs say that

    $png = $pdf->image_png($file) Imports and returns a new PNG image object.
    but, $file may mean a disk file. Quite possibly you cannot use an in-memory image. The docs would probably say $data if they accepted binary streams.

    You might look into whether you can convert to Base64encoded images, and whether you can use that format. Or use File::Temp and just write to a temporary disk file.


    I'm not really a human, but I play one on earth.
    Old Perl Programmer Haiku ................... flash japh
Re: PDF::API2 and Imager
by philiprbrenan (Monk) on Aug 29, 2012 at 14:11 UTC

    Please run perl -d on your script and see if you can get a stack back trace from the debugger as this will help localize the problem. Are you sure that $img and $result are defined?