# How to fix/repair a corrupted PDF file

ghostscriptpdfrepair

Does anyone have any recommendation or procedures for repairing a corrupt PDF? When I open the file I get "There was an error opening this document. the file is damaged and cannot be repaired." There seems to be a myriad of tools out there but none that I could describe as reputable. Are there any opensource linux based solutions for this possibly?

Ghostscript will repair your corrupted PDF automatically... if it can open it in the first place (that is, if it is not damaged beyond repair). But afterwards you'll still need to double-check the result...

On Linux, try this command:

 gs \
-o repaired.pdf \
-sDEVICE=pdfwrite \
-dPDFSETTINGS=/prepress \
corrupted.pdf


On Windows, try this one:

 gswin32c.exe ^
-o repaired.pdf ^
-sDEVICE=pdfwrite ^
-dPDFSETTINGS=/prepress ^
corrupted.pdf