ssimms / pdfapi2

Create, modify, and examine PDF files in Perl
Other
15 stars 20 forks source link

PDF::API2 making pdf's that CUPS can not print #53

Open iqvoice opened 2 years ago

iqvoice commented 2 years ago

I wrote some perl code about ten years ago that uses PDF::API2 to open an existing pdf, add some stuff, and save it as a new pdf. (basically using a template to do fill-in-the-blanks) and then sending the new pdf to CUPS for printing. This has worked fine for all these years! (thanks!) But this week I upgraded the system OS from Debian Buster to Bullseye, and with that upgrade I had to re-install all of my CPAN modules including PDF::API2. After the OS upgrade, something is broken. The saved PDF can not be printed by CUPS (doesn't seem to matter what printer, I tried several). I think this is the relevant error from the CUPS log:

E [22/Aug/2022:18:47:35 -0400] [Job 6462] loadFilename failed: /var/spool/cups/d06462-001 (offset 79458): unable to find /Root dictionary

That is a very obscure error, I can only find maybe 4 hits in all of google. So I'm really not sure if this is CUPS or PDF::API2. However, the following tidbits led me to think it was PDF::API2. 1) CUPS can still print the original (ten year old) template file, it's only the new files made by PDF::API2 that won't print. 2) if I trim out a section "<< ,,, >>" of the new PDF that contains the string "/Root", the file becomes printable, 3) the new pdf contains multiple %%EOF. I dont know much PDF but I think it should only have one?

If you want a look at the template PDF, the resulting PDF, or my code, I will snip it together and post it here.

Thanks!

iqvoice commented 2 years ago

I almost forgot important details. I re-wrote my code to not use the template file, instead I just create a new PDF and add some stuff to it in code to make up the difference. This worked fine w/ PDF::API2, and CUPS was happy to print it. So the problem seems to be around the opening of the old PDF, parsing its innards, and saving it to a new PDF.

ssimms commented 2 years ago

I'll need enough information to be able to reproduce the issue in order to do any real troubleshooting. PDFs can contain multiple %%EOF sections, and this is normal for PDFs that have been modified.

Make sure you're using the latest version of PDF::API2 (2.043). Debian Bullseye comes with 2.038, which is two years old. 2.039 included changes that improved the use case you're talking about.

This command will show the installed version:
perl -MPDF::API2 -E 'say $PDF::API2::VERSION'

iqvoice commented 2 years ago

Checked, and I am using version 2.043. Note that I installed from CPAN and not with a Debian package. Trying to cut out a section of my code and have it reproduce the problem has been difficult, because it's not reproducing the problem! So that's weird and I'm still working that. But here are the two PDFs that started it all: the template, and the output pdf that won't print. for_printer.pdf template.pdf