Forum


Replies: 4   Views: 670
How to repair a pdf that can't be merged
Topic closed:
Please note this is an old forum thread. Information in this post may be out-to-date and/or erroneous.
Every phpdocx version includes new features and improvements. Previously unsupported features may have been added to newer releases, or past issues may have been corrected.
We encourage you to download the current phpdocx version and check the Documentation available.

Posted by pks  · 25-08-2021 - 20:21

I'm trying to merge multiple PDFs with MultiMerge mergePdf() function, which works most of the time. In a specific case/file, the process fails with this error:

Fatal error: Uncaught exception 'Exception' with message 'TCPDF_PARSER ERROR: decodeFilterFlateDecode: invalid code' 

I've followed the tutorial here:
https://www.phpdocx.com/documentation/cookbook/repair-PDF
and in case the merging process fails, I automatically repair all pdfs with pdftocairo then I try to merge again. WIth the repaired PDFs now I get to a different error, an infinite loop crash:

http://prntscr.com/1qiino1

Furthermore, I discovered that even with good files that can be merged by phpdocx, if I go through the pdftocairo repair process before, I get to the exact same infinite loop that ends with an out of memory error.

Is this a corrupted file issue, pdftocairo messes up the files worse than they are? Both the original and the repaired pdfs open fine in readers, browsers, etc. Has anyone experienced anything similar? I can provide the file in case on private if needed.

Posted by admin  · 26-08-2021 - 05:37

Hello,

Please try using the following command to repair the PDF that uses ghostscript instead of pdftocairo:

gs -o document_repaired.pdf -sDEVICE=pdfwrite -dPDFSETTINGS=/prepress document.pdf

If you send the PDF document to contact[at]phpdocx.com we'll check it.

Regards.

Posted by pks  · 26-08-2021 - 08:25

Thank you for the quick reply and suggestion - it worked! If it's not too much trouble, I would advise completing this article:

https://www.phpdocx.com/documentation/cookbook/repair-PDF

with the Ghostscript idea and command line, it could save hours of debugging for other users.

Posted by admin  · 26-08-2021 - 08:42

Hello,

The page has been updated in the current testing branch of the website, it will be updated in the coming days.

Regards.