If you’ve ever tried opening a PDF and got the dreaded ‘Invalid header’ error, you know the panic. The file won’t display, and you worry your data is gone. This guide is for anyone facing that error—whether you downloaded a corrupted file, transferred it improperly, or it got cut off. By the end, you’ll have a repaired PDF that opens normally, using free tools you can run on any operating system.
We’ll fix the header manually with a hex editor, then use command-line utilities like qpdf and pdftk to rebuild the file structure. No coding experience required—just follow along step by step. You’ll also learn how to avoid making things worse and what to try if the header repair alone isn’t enough.
What You’ll Need
- A backup copy of the corrupted PDF (always keep the original!)
- A hex editor (we recommend HxD for Windows, Hex Fiend for macOS, or xxd on Linux)
- qpdf command-line tool (free, install via package manager or download from sourceforge)
- pdftk (optional, if qpdf doesn’t fully repair the file)
- A PDF viewer (like Adobe Acrobat, Chrome, or Okular)
Step 1: Identify the Invalid Header

Open the PDF in your hex editor. The file should start with ‘%PDF-1.’ followed by the version number (like ‘1.4’). If you see anything else—garbage characters, zeros, or a different text string—the header is invalid. Also check that there’s a newline character (0x0A) after the version line. If not, that can cause the error too.
Make a note of the correct version you expect. Most modern PDFs are 1.4 or higher. If you’re unsure, try 1.4 first—it’s widely compatible.
Step 2: Fix the Header Manually with a Hex Editor

In your hex editor, select the first few bytes that are corrupt and replace them with the correct header. Type: ‘%PDF-1.4’ followed by a newline (0x0D 0x0A on Windows, or just 0x0A on Mac/Linux). Be careful not to delete any bytes after the header—only overwrite the corrupt ones. Save the file as a new copy (don’t overwrite the original).
If the file’s very first bytes are zeroes or random data, you may need to insert the header instead of overwriting. Most hex editors allow insertion. Insert ‘%PDF-1.4
‘ at position 0 and shift the rest of the file accordingly. Then save.
Step 3: Use qpdf to Repair the Structure

Open a terminal or command prompt. Run: qpdf --linearize input.pdf output.pdf. This linearizes the PDF, rebuilding cross-references and fixing internal links. If the header was the only issue, qpdf often produces a fully working file. If you get errors about other corruption, try the --qdf mode: qpdf --qdf input.pdf output.pdf to create a more healable format.
For more severe corruption, refer to our guide on how to repair a corrupted PDF using similar techniques. Also, the open source PDF repair article covers many free tools like qpdf and poppler-utils.
Step 4: Try pdftk if qpdf Fails
If qpdf can’t fix the file, install pdftk and run: pdftk input.pdf output output.pdf. Pdftk often recovers pages even when the header is bad because it parses the file more leniently. If that still fails, try pdftk input.pdf cat output output.pdf to reassemble without modification.
Pdftk is also useful when you want to fix a damaged PDF that has other structural issues. And if you see error codes like 109 during repair, check our specific repair PDF error 109 guide.
Step 5: Verify the Repaired PDF
Open your output PDF in a viewer. If it displays correctly, you’re done! Check that all pages are present and text is selectable. If you still see issues, try the --check option in qpdf: qpdf --check output.pdf to see remaining warnings. Sometimes a second pass with different tools can finish the repair.
You can also try using Poppler’s pdfinfo or pdftotext to extract data. For more on that, see how to repair PDF with Poppler.
Common Pitfalls
- Using the wrong PDF version: If the original used a higher version (like 1.7) and you wrote 1.4, some features may not work. Check the original file’s metadata if possible, or try a few different versions.
- Accidentally deleting extra bytes: When overwriting/inserting the header, make sure the total file size doesn’t change unexpectedly. Always keep a backup.
- Assuming header is the only issue: Often an invalid header comes with corrupted cross-reference tables or objects. Use qpdf and pdftk as described to fix deeper problems.
Where to Next
Now that you’ve fixed the header, you might encounter other PDF errors. Check out our guides on repairing specific issues like blank pages or symbols instead of text. And remember, the best way to avoid header corruption is to always save PDFs properly and use reliable transfer methods.