Repair PDF
Rebuild damaged or truncated PDFs so they open again
Files are processed only in this browser. Nothing is uploaded to a server.
Rebuild PDFs with a broken xref or truncated data by scanning their objects so they open again
This PDF is password-protected.
Continue in another tool
Processing…
Everything runs inside this browser. Your file is never sent to a server.
Your file is ready to download
Continue with this result
Open page preview
Changing a setting hides the previous result. Run it again to save the latest settings.
Remove the password from an encrypted PDF first. Processing focuses on page content, so bookmarks, attachments, forms and signatures may not be preserved. Keep the original and check the result.
Working…
0.0
It hasn't frozen — the result will appear when the calculation finishes.
About Repair PDF
A PDF isn't read from top to bottom. Near the end of the file sits a cross-reference table (xref) that lists the byte offset of every object, along the lines of 'object 3 starts at byte 1,204'. A viewer starts at the trailer at the end and jumps to objects by those addresses. So a file whose content is perfectly intact can still be reported as damaged if that address book is wrong.
This tool doesn't trust the address book. It scans the whole file from start to finish, finds every object wrapped in 'N 0 obj … endobj', and writes a fresh cross-reference table from what it found. After saving, it reopens the result with a PDF engine and checks the page count.
Damage that can be fixed
The tool targets cases where the structural information is wrong but the data is still there. That also happens to be the most common kind of damage.
- Junk before the header. When a mail gateway or upload script prepends bytes before %PDF-, every offset shifts by the same amount. Stripping the prefix fixes it.
- Wrong xref offsets. Another program edited the file without updating the table, or a line-ending conversion (an FTP transfer in text mode, for example) moved bytes around.
- Wrong stream length (/Length). If /Length doesn't land on endstream, the tool looks for endstream and measures again.
- Missing trailer. /Root is taken from the last trailer or xref-stream dictionary; failing that, the tool searches for a /Type /Catalog object and uses it as the document's entry point.
- Broken page tree. Entries pointing to pages that don't exist are dropped and /Parent and /Count are corrected. If there's no usable tree, a new one is built from the /Type /Page objects in file order.
Damage that can't be fixed
Bytes that are gone can't be recovered. If a download stopped at 60%, the objects in the last 40% aren't anywhere in the file. A page object may survive while its content stream or images were in the missing part, and that page will open blank or without pictures.
Since PDF 1.5, many objects can be packed into a single compressed object stream (ObjStm). If one of those is cut off, dozens of objects disappear with it. The tool can only unpack object streams compressed with FlateDecode; ones using other filters or predictors can't be recovered.
Encrypted PDFs are out of scope because the object contents are locked. Corruption inside compressed data, such as flipped bits, can't be fixed by rebuilding structure either.
Incremental updates and 'the last definition wins'
PDF allows incremental updates: changes are appended to the end of the file instead of rewriting it. Add a signature or a comment and the same object number can appear two or more times, and per the spec the later one is the live version. The tool follows the same rule and uses the last definition of each object number in the file.
As a result, the repaired file reflects the most recent save. If the last incremental save was cut off partway, the truncated objects are dropped and the older, complete definitions win, so you may see the document one step back. It also means older versions of objects are still sitting in the file, and content you thought you'd deleted can resurface during recovery.
Worked examples
A contract from an email that won't open
- Input
Diagnosis: 16 bytes of junk before %PDF; 30 of 30 xref offsets don't match- Output
Leading 16 bytes removed, new xref written for 38 objects, 12 pages confirmed
When every offset is wrong by the same amount, something was stuck on the front. No data was lost, so the result is the same document as the original.
A report whose download was interrupted
- Input
12 MB received of a 20 MB file, no trailer- Output
Truncated objects discarded, root recovered by finding the catalog, some pages blank
Only objects that were wholly inside the first 12 MB survive. Pages whose images sat further back open blank. If you can download the original again, that's the real fix.
Pages not linked into the tree
- Input
Page tree lists 10 pages; the file holds 12 page objects- Output
With the option on, 2 pages are appended at the end
These are most likely pages deleted during editing that incremental saves left behind. Append them, check what they are, and remove them if they're not needed.
How to use it
- Add the PDF that won't open and read the diagnosis list.
- If there are pages not linked into the tree, decide whether to append them at the end.
- Run the repair, check the verified page count and preview, then download the PDF and the report.
Key terms
- Cross-reference table (xref)
- A list of the byte offset where each object starts. From PDF 1.5 it can also be stored as a compressed xref stream.
- Incremental update
- Saving by appending changed objects and a new xref section to the end of the file instead of rewriting it.
Frequently asked questions
Will repairing a corrupted PDF bring it back exactly?
If only the addresses were wrong, yes. Data that was cut off doesn't come back.
It opens in one viewer but not another. Why?
Viewers differ in how much damage they tolerate. Lenient ones quietly do a similar rescan; writing a clean xref with this tool usually lets stricter viewers open it too.
Is the signature still valid after repair?
No. The file is rewritten, so digital signatures become invalid. If you need a verifiable signature, ask the sender for a fresh copy.
Can the page order change?
If the tree is intact, the original order is kept. Only when the tree has to be rebuilt does it follow file order, which can differ.
Sources
- Adobe — PDF 1.7 / ISO 32000-1:2008, 7.5 File structure (xref, trailer, incremental updates, object streams)
- PDF Association — ISO 32000 (PDF) resources
- PDF Association — Preparing for PDF files from the future
- pdf-lib — PDFDocument
Last reviewed: