If your PDF refuses to open and spits out a cryptic error like ‘Cross-reference table is missing’ or ‘Invalid xref entry’, you’re in the right place. This guide is for anyone who has a partially corrupted PDF and wants to recover it without paying for expensive software. By the end, you’ll have a working PDF file again, either by using the command-line tool qpdf or by manually editing the xref table with a hex editor.
The xref (cross-reference) table is like the index of a PDF – it tells the reader where every object in the file is located. When it gets corrupted, the PDF becomes unreadable. We’ll walk through two methods: the easy automatic fix with qpdf, and a more hands-on approach for tougher cases. Both are free and tested.
What You’ll Need
- qpdf command-line tool (free, for Windows/Mac/Linux) – download from sourceforge.net/projects/qpdf/
- A hex editor (e.g., HxD for Windows, Hex Fiend for Mac, or any similar tool)
- Backup of your original PDF file – never work on the only copy
- Optional: a viewer like Adobe Acrobat or a browser to test the repaired file
If you prefer a GUI tool, you can also use the mutool repair pdf method covered in another guide.
Step 1: Diagnose the Xref Error
First, confirm that the xref table is indeed the problem. Open your PDF in a viewer and note the error message. If it mentions ‘cross-reference’, ‘xref’, or ‘missing object’, you’re on the right track. Alternatively, run this qpdf command to check the file:
qpdf --check broken.pdf
This will output any errors found. Look for lines like ‘WARNING: broken.pdf: cross-reference table is missing’ or ‘xref table inconsistencies’. If you see those, proceed to Step 2.

Step 2: Automatic Repair with qpdf
qpdf can often rebuild a corrupted xref table automatically. Use the –repair flag:
qpdf --repair broken.pdf fixed.pdf
This command creates a new file called fixed.pdf with a regenerated xref table. If the repair succeeds, you’ll see no warnings. Open fixed.pdf in a viewer to verify it works. If you’re still getting errors, try the scan pdf for errors technique to dig deeper.

Step 3: Manual Fix with a Hex Editor (Advanced)
If automatic repair fails, you may need to manually edit the xref table. This is more technical but often works when the file is severely mangled. First, make a backup of the original file. Then open the PDF in your hex editor.
The xref table usually appears near the end of the file, introduced by the keyword xref. For example:
xref
0 6
0000000000 65535 f
0000000009 00000 n
0000000100 00000 n
...
Each entry has the byte offset (10 digits), generation number (5 digits), and a flag (n = in use, f = free). If you see garbage characters or missing entries, you can reconstruct them by searching for each object’s obj keyword in the file, recording its byte position, and then writing the correct entry in the xref table.
Important: The trailer must have the startxref keyword followed by the byte offset of the xref table itself. Also ensure the file ends with %%EOF. A common mistake is forgetting the trailing whitespace after %%EOF. Check the pdf parse error fix guide for more on adjusting these offsets.

Step 4: Verify the Fix
After manual editing or qpdf repair, always verify the file:
qpdf --check fixed.pdf
If no errors appear, try opening the PDF in multiple viewers (Adobe Acrobat, browser, etc.). If it works in at least one, you’re good. For extra safety, you can also use the repair pdf after download approach to clean up any remaining issues.

Common Pitfalls
- Missing %%EOF: The PDF must end with exactly %%EOF plus an optional line break. Without it, the reader can’t find the trailer. Always double-check.
- Wrong byte offsets: A single off-by-one error in an xref entry will corrupt the whole file. Use the hex editor’s status bar to get precise positions.
- Overwriting adjacent data: When inserting or fixing bytes, you may shift the positions of other objects. If you add or remove bytes, you’ll need to update all offsets in the xref table – that’s why automatic tools are safer.
If you accidentally destroy the file beyond repair, try to recover 0kb pdf as a last resort – sometimes the data is still there, it just looks empty.
Where to Next
Fixing the xref table is just one type of PDF repair. If you’re dealing with other issues like corrupted streams, missing fonts, or broken links, check out the related guides on this site. And remember: always keep backups!