coherentgraphics / cpdf-binaries

PDF Command Line Tools binaries for Linux, Mac, Windows
Other
581 stars 42 forks source link

Errors when further processing merged PDFs #49

Closed micschk closed 3 years ago

micschk commented 3 years ago

(Commercial license, CPDF v2.3.1) We see a strongly increased amount of errors when further processing merged PDFs in cpdf. error Pdf.PDFError("Could not extract object"), will read as malformed

What we do is first merge a bunch of PDFs into one (works without problem). The errors occur when we further process the merged file, usually at the point where we -pad-after some blank pages, or -add-rectangle to a -range of pages (I guess at the point where the PDF actually has to be rendered by CPDF?).

Various errors may or may not occur at this point:

Processing all 'source' PDFs of the merged PDF individually with -pad-after and -add-rectangle works without any problems, my guess is that the merging somehow causes malformations. The resulting PDF seems to render just fine in eg Chrome. Also, when re-running the exact same steps again they may work just fine, or result in a comparable error (but not exactly the same).

Example output when using -gs-malformed;

Error: /ioerror in --runpdf--
Operand stack:
   --dict:10/19(L)--   --dict:1/1(L)--   0   false   1   1   1   0   --nostringval--
Execution stack:
   %interp_exit   .runexec2   --nostringval--   runpdf   --nostringval--   2   %stopped_push   --nostringval--   runpdf   runpdf   false   1   %stopped_push   2045   1   3   %oparray_pop   2044   1   3   %oparray_pop   2025   1   3   %oparray_pop   2026   1   3   %oparray_pop   runpdf   runpdf   49   1   82   runpdf   %for_pos_int_continue   runpdf   runpdf   runpdf   runpdf   runpdf   %loop_continue   runpdf   --dict:3/3(L)--   runpdf   3   %dict_continue   runpdf   runpdf   runpdf
Dictionary stack:
   --dict:970/1684(ro)(G)--   --dict:1/20(G)--   --dict:82/200(L)--   --dict:82/200(L)--   --dict:133/256(ro)(G)--   --dict:313/450(ro)(G)--   --dict:30/32(L)--   --dict:0/6(L)--
Current allocation mode is local
ERR OUTPUT: list length 0
Because of error Pdf.PDFError("Could not extract object"), will read as malformed.
Attempting to reconstruct the malformed pdf /path/to/MergedPdf.201008075805.pdf...
list length 0
CPDF could not mend. Attempting to mend file with gs
GPL Ghostscript 9.26: Unrecoverable error, exit code 1
Could not fix malformed PDF file, even with gs
johnwhitington commented 3 years ago

I'm sure that this can be diagnosed and fixed easily, but I won't be able to do it without example files. Can you send me by email (john at coherent graphics dot co dot uk) a selection of input files, together with the merge command, and a subsequent command which fails?

(Your intuition that merging doesn't require 'rendering' and that, therefore, malformities in files can survive merging only to be problematic later is correct, by the way).