Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.

Error opening output from PDF::API2

by buckaduck (Chaplain)
on May 07, 2019 at 22:07 UTC ( #1233444=perlquestion: print w/replies, xml ) Need Help??

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

The very simple code below runs without errors, but the output file cannot be opened by Adobe:

use PDF::API2; my $pdf = PDF::API2->open("test.pdf") or die $@; $pdf->saveas("test2.pdf");

Adobe Standard 2017 gives this error when I try to open test2.pdf: "There was an error opening this document. There was a problem reading this document (14)." I tried it using a variety of different input PDF files; it makes no difference. I'm using a very recent installation of StrawberryPerl 5.28.1 on Win10, and the PDF::API2 module version 2.033.


Replies are listed 'Best First'.
Re: Error opening output from PDF::API2
by snoopy (Curate) on May 08, 2019 at 00:46 UTC
    Thanks for the code sample. I am able to replicate this problem, but on PDF 1.5+ files with cross reference streams only.

    PDF::API2 is attempting to do an incremental-update; i.e. doing a byte-copy of the entire file, then writing just an update section.

    One issue I can see is in the trailer. PDF::API writes:

    xref 0 1 0000000000 65535 f trailer << /Type /XRef /DecodeParms << /Columns 4 /Predictor 12 >> /Filter /Fl +ateDecode /ID [ <0804b5bbf3a55e75ca368be05a5dbdf1> <49e68ac26e773d479 +329dad137f869c3> ] /Index [ 214 37 ] /Info 213 0 R /Length 86 /Prev 1 +16 /Root 215 0 R /Size 250 /W [ 1 2 1 ] >> startxref 106778 %%EOF
    But the format should be more like:
    xref 0 1 0000000000 65535 f trailer << /ID [ <0804b5bbf3a55e75ca368be05a5dbdf1> <49e68ac26e773d479329dad13 +7f869c3> ] /Info 213 0 R /Prev 116 /Root 215 0 R /Size 250 >> startxref 106780 %%EOF
    It's leaving some irrelevant 1.5 entries in the file trailer (/Type, /Columns, /Predictor, /Filter, /Index, /Length /W ...) when writing a 1.4 format trailer. Could be other issues.

    Needs a ticket. I'll raise one when I get some clicks.

    In the short term you can try converting the PDF files to 1.4 and see if that helps.

    Update: The Perl 6 PDF module also has similar issues (I'm the author). I've raised a ticket there first.

    - hopefully fixed in Perl 6
    - There is already an open ticket (with a proposed solution) in PDF::API2 that I missed earlier.

      Thanks, snoopy! Yes, if I convert the source PDF to 1.4 then it works! It's a nice workaround for now.


Log In?

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (2)
As of 2023-09-30 17:04 GMT
Find Nodes?
    Voting Booth?

    No recent polls found