"There was an error opening this document. The file is damaged and could not be repaired." Few messages are more alarming when the PDF is an invoice you need to pay, a signed agreement or the only copy of a report. Sometimes the file opens in one app but not another, shows blank pages, or stops partway through.
The good news is that a large share of "corrupted" PDFs still contain all or most of their content. What is broken is usually the index that tells a viewer where things are. This guide explains how a PDF is structured, what typically goes wrong, how to diagnose and rebuild a damaged file in your browser, and when recovery is simply impossible.
How a PDF is put together
A PDF file has four main parts:
- Header: the first line, such as
%PDF-1.7, which identifies the file type and version. - Body: numbered objects containing pages, fonts, images, text streams and so on.
- Cross-reference table (xref): an index listing the exact byte position of every object in the file.
- Trailer: points to the root object and to where the cross-reference table starts, using a
startxrefline, and ends with%%EOF.
A viewer normally reads the file from the end: it finds %%EOF, reads startxref, jumps to the index and uses it to load objects on demand. If any link in that chain is broken, a strict viewer gives up, even though the actual pages may be sitting untouched in the body.
What causes PDF corruption
| Cause | Typical symptom | What is damaged |
|---|---|---|
| Interrupted download or upload | Error on opening; file smaller than expected | End of file missing: no %%EOF, no index |
| Email or messaging app mangling | "Damaged" error; odd characters at start | Bytes altered or added before the header |
| App crashed while saving | Opens in some viewers, not others | Index points to wrong positions |
| Disk full, failing USB stick or card | Random errors, missing pages | Parts of the body overwritten or missing |
| Server adding output before the file | "Not a PDF" error | Junk bytes before %PDF |
| Incomplete sync from cloud storage | Blank or partial pages | Truncated body |
Notice that only the last few involve content that is actually gone. Broken indexes and junk bytes are repairable; missing data is not.
Try these first
Before any repair tool, rule out the simple causes:
- Download or copy the file again. Most "corruption" is an incomplete transfer. Compare file sizes with the sender if you can.
- Open it in a different viewer. Browser viewers, including those based on pdf.js, can often rebuild a broken index on the fly. If it opens in a browser, you may only need a clean copy.
- Ask the sender to re-export. If the document was generated by an app, a new export is better than any repair.
- Check for encryption. A password-protected file that will not open may simply need its password. Encrypted files must be unlocked with Unlock PDF before a structural repair.
Repair a damaged PDF step by step
Repair PDF inspects the file, reports what it finds and rebuilds a clean copy where possible, all in your browser.
- Open Repair PDF and drop the damaged file onto the box.
- Read the Diagnosis list. It checks whether the
%PDFheader is present and whether junk bytes precede it, whether the%%EOFend-of-file marker exists, and whether thestartxrefpointer is intact. It then reports what each of two PDF engines could read. - If the structure could be rebuilt, click Download repaired PDF. The button shows how many pages were recovered. This copy is written from scratch with a new, valid index and keeps text, images and links. The tool re-opens the output to confirm it loads.
- If only one engine could display the pages but the structure could not be rebuilt, click Re-draw pages as images for a last-resort copy. Pages will look right but their text is no longer selectable.
- Open the repaired file in your usual viewer and check every page before deleting the original.
Reading the diagnosis
- Header missing or junk before it: often caused by a server or script adding output before the file. Stripping the junk usually fixes it completely.
- No
%%EOFmarker: the file is truncated. Pages near the end may be missing; earlier pages can often be recovered. - No
startxrefpointer: the index location is lost, and the file must be scanned from top to bottom to find objects. This is exactly what the rebuild does. - One engine reads it, the other does not: the file is inconsistent. The tool uses whichever engine reaches the pages.
- Neither engine reads any page: the content is too damaged or missing, and no repair tool can invent it.
Other repair methods
Print to PDF from a viewer that opens it
If any viewer can display the file, printing it to a PDF printer produces a new, structurally clean file. It may re-render content and lose links, bookmarks and form fields, so a proper rebuild is preferable when available.
Command-line tools
qpdf attempts recovery automatically when it reads a damaged file, so simply rewriting it can produce a clean copy:
qpdf damaged.pdf repaired.pdf
Ghostscript can also rewrite a file through its PDF output device. Both are excellent for batches but require installation.
Recovery from backups and versions
Cloud storage and some operating systems keep previous versions of files. If a document was corrupted by a failed save, restoring an earlier version gives you the real original, which beats any repair.
When repair is not possible
Be realistic about what repair can do:
- Truncated files lose whatever was never written. If the transfer stopped at 60%, the last 40% of the content is not there.
- Overwritten data on a failing drive is gone.
- Files that were never PDFs, such as an error page saved with a
.pdfname, cannot be turned into the document you expected. Open the file in a text editor: if it starts with<htmlrather than%PDF, it is a web page.
In these cases, go back to the source: the sender, the original app or a backup.
After a successful repair
- Keep the original until you are sure the repaired file is complete.
- Check page count against what you expect. If pages are missing from the rebuilt copy but visible in a viewer, the image fallback may recover them.
- Reduce the file if it grew during repair using Compress PDF.
- Check document details such as title and author with PDF Metadata Editor, since rebuilding writes a fresh file.
Frequently asked questions
Can every corrupted PDF be repaired?
No. A broken index or junk bytes can usually be fixed, but content that was never written or has been overwritten cannot be recovered by any tool.
Why does my PDF open in the browser but not in my desktop app?
Browser viewers are often more tolerant and rebuild a broken index silently. Rebuilding the file into a clean copy lets strict viewers open it too.
Will the repaired PDF keep selectable text?
Yes, when the structural rebuild succeeds. Only the last-resort re-draw option turns pages into images without selectable text.
Can I repair a password-protected PDF?
Not while it is encrypted. Remove the password with the correct credentials first, then repair the unlocked copy.
Is my damaged file uploaded for repair?
No. The diagnosis and rebuild run entirely in your browser.