Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

Image errors with PDF::API2;

by djlerman (Sexton)
on Nov 15, 2021 at 23:15 UTC ( [id://11138860]=perlquestion: print w/replies, xml ) Need Help??

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

I have a script that uses the PDF::API2 module. Two errors have recently shown up.
[3350]ERR: 24: Error in Perl code: Unsupported Interlace(1) Method at +/usr/share/perl5/vendor_perl/PDF/API2/Resource/XObject/Image/ l +ine 45.
[16820]ERR: 24: Error in Perl code: 16-bits of rgb+alpha in png not su +pported. at /usr/share/perl5/vendor_perl/PDF/API2/Resource/XObject/Im +age/ line 204.
Is there a way to correct these errors or should I not allow the upload of .png images?

Replies are listed 'Best First'.
Re: Image errors with PDF::API2;
by kcott (Archbishop) on Nov 16, 2021 at 05:23 UTC

    G'day djlerman,

    It would be useful if you supplied some simple code demonstrating the generation of these errors. Also, please let us know the version of PDF::API2 that you are using; other similar information, such as Perl version and OS may be helpful.

    I had a look at the source: The line numbers you show don't seem to fit the messages (so you're probably not using the latest 2.042 version).

    I did note at lines 84-89:

    # BPC = bits per component, and may be 1, 2, 4, 8, or 16 per the PNG s +pec. # Color types may further restrict the available options. Additionall +y, # this module doesn't currently support 16-bit components. if ($bpc == 16) { die '16-bit colors/transparency are not supported.'; }

    That was the only thing that matched a search for "not supported". Have a look around your own version of the source code: searching for "not supported" or "Unsupported" may shed some light on the problem.

    — Ken

      Thank You Ken. :-)

      PDF::API2 -- 2.021
      perl -- v5.10.1 (*) built for x86_64-linux-thread-multi
      os -- CentOS release 6.5

      Here is code:
      use PDF::API2; use constant mm => 25.4 / 72; use constant in => 1 / 72; use constant pt => 1; # Create a blank PDF file my $pdf = PDF::API2->new(); # Add a blank page my $page = $pdf->page(); # Set the page size $page->mediabox('Letter'); $pdf->info( 'Author'=>'COPA', 'Title'=>'perl PDF API2 Test', ); $imageFile = "/home/images/test.png"; $img = $pdf->image_png($imageFile); $image = $page->gfx; $image->image($img, 0/mm, 100/mm); # print output $http_headers_out{'Content-Disposition'} = "inline; filename=pdfTes +t.pdf"; $http_headers_out{'Content-type'} = "application/pdf"; $escmode = 0; print OUT $pdf->stringify; $pdf->end;
Re: Image errors with PDF::API2;
by tangent (Parson) on Nov 16, 2021 at 20:32 UTC
    I tried your code with two 24bit images, one interlaced the other not. It worked fine with the non-interlaced image but failed with the same error as yours for the interlaced image.

    I was able to get it working by using GD to handle the image:

    use GD; # ... my $imageFile = "image-24bit-interlaced.png"; my $gdimg = GD::Image->new($imageFile); my $img = $pdf->image_gd($gdimg); my $image = $page->gfx; $image->image($img, 0/mm, 100/mm);
    It produced a new PDF with the image placed. I did get a warning though:
    libpng warning: Interlace handling should be turned on when using png_read_image
    This is a bug in libpng addressed in this discussion.

    PS the module version you are using is very old - if you are planning to use it more you should update to the latest version. If you do you will need to update a few lines of your code also.

      Everything involved here is very old. Going by the info from elsewhere in the thread this is running on Centos 6 (edit and even an extremely ancient version of that, 6.5 rather than the "latest" 6.10) which went EOL just shy of a year ago (see here). OP would be much better served getting onto a newer platform and trying to get things working there rather than attempting to work around decade-ish old bugs.

      The cake is a lie.
      The cake is a lie.
      The cake is a lie.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://11138860]
Approved by kcott
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (2)
As of 2024-07-14 13:30 GMT
Find Nodes?
    Voting Booth?

    No recent polls found

    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.