Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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?

share|improve this question
    
Opensource PDF tools tend to be pretty crappy, I'm afraid. What are you using? –  Satanicpuppy May 3 '11 at 14:38
    
Also see: superuser.com/questions/166999/… –  slhck May 3 '11 at 14:39
    
didnt like the look of any of the tools as they looked like the myriad of "Registry Cleaners" out there that are useless. Have been trying Adobe Pro and have just started looking if Ghostscript or PDFForge have any repair switches. –  Tim Alexander May 3 '11 at 14:48
    
Ghostscript is okay, but it's certainly not better than Acrobat. It's completely bare bones. –  Satanicpuppy May 3 '11 at 18:41
1  
@Satanicpuppy I disagree :: I use ghostscript to rebuild damaged or low-quality pdfs quite often and it performs very well. –  Eddie B Feb 5 '13 at 20:16

4 Answers 4

up vote 41 down vote accepted

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
share|improve this answer
    
Ghostscript does a fantastic job of rendering pdfs ... I regularly use gs to rebuild pdfs to improve font quality. –  Eddie B Feb 5 '13 at 20:14

I had a corrupted PDF file, print.pdf , that Ghostscript couldn't open, but the usual graphical Linux PDF viewers (Okular, Evince) opened fine. (In my case, the file had garbage at the start instead of a PDF header, when opened in a hex editor.)

These PDF viewers use Poppler as a back-end PDF renderer. So you can repair the PDF using Poppler's command-line tools. In Ubuntu these are in the poppler-utils package. I used:

pdftocairo -pdf print.pdf print_repaired.pdf

which generated a PDF file with correct headers, which tools like Ghostscript now accepted.

share|improve this answer
2  
+1 this read my Quartz generated PDF without complaints, and immediately started generating output. Ghostscript, Adobe Acrobat Pro and others insisted on rebuilding my 120GB pdf first. –  Orwellophile Dec 14 '13 at 14:17
    
This didn't work for at least one weird PDF I came across, but it seems like a good start. –  Bepetersn Nov 11 '14 at 20:00
    
Works perfectly on a PDF on which Ghostscript wanted to remove some arbitrary elements on pages. –  Andrea Lazzarotto Nov 22 '14 at 16:14

I had a corrupted pdf file, because the php file used to download it echoed some errors (in HTML) and NUL characters at the end.

The solution was to open the pdf with Notepad++ and remove all text after the line

%%EOF
share|improve this answer
    
had same, Adobe Reader didn't open but native Mac, Chrome and Firefox PDF plugin displayed PDF file fine. Reason was also extra "NUL" at last line added during the upload. –  Tilo Apr 8 '14 at 19:23

mutool (project page, manpage) will repair broken PDFs without printing them.

  • Installation e.g. on Ubuntu: sudo apt-get install mupdf-tools
  • Run it like this: mutool clean input.pdf output.pdf
mutool clean [options] input.pdf [output.pdf] [pages]

  The clean command pretty prints and rewrites the syntax of a PDF file.
   It can be used to repair broken files, expand compressed streams,
   filter out a range of pages, etc.
  If no output file is specified, it will write the cleaned PDF to
   "out.pdf" in the current directory.
share|improve this answer
1  
This solution works "better" than the solutions offered above or better ranked, as it does not "print" the PDF file and keeps active the links, clickable items, etc... To me, it sounds a more elegant solution than using ghostscript or cairo. –  Speredenn Jun 5 at 15:21

protected by Community Nov 15 '12 at 7:18

Thank you for your interest in this question. Because it has attracted low-quality answers, posting an answer now requires 10 reputation on this site.

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.