Cookbook

Repair PDF documents

Working with PDF methods such as mergePdf or sign (PDF), requires the documents to be internally correct, that means well-formed, uncorrupted and unprotected.

To repair a PDF document that is not well-formed, the easiest approach is using ghostscript, available for Windows, Linux and macOS.

After installing ghostscript, the command to repair a PDF is:

This command can be called from PHP using passthru or exec functions.