What this covers

  • A second reader is the first and cheapest test
  • An interrupted download is the most common cause by a distance
  • Repair rebuilds the index; it cannot recover data that never arrived
  • A file that asks for a password is not damaged

A file that will not open at all looks like total loss and usually is not. In most cases the content is intact and the index that tells a reader where to find it is damaged - which is a recoverable situation, and one with an unusually clear diagnosis.

The diagnosis, in order

About a minute.

  1. Open it in a second reader

    A surprising proportion of these are one reader disagreeing with an unusual but valid file. If a second reader opens it, use that one and stop.

  2. Check the file size

    A zero-byte or suspiciously small file never downloaded. A file about the right size that will not open is a damaged index.

  3. Check whether it is asking for a password

    An encrypted file is not damaged. It needs the password, and no repair will substitute for one.

  4. Check it is actually a PDF

    A file renamed to .pdf is still whatever it was. If it was saved from a page that returned an error, it may be an HTML error page with the wrong extension.

  5. Re-download from the original source

    Better than any repair, if the source is still available. This is the fix people skip in favour of more interesting ones.

  6. Repair it

    If the source is gone. The index is rebuilt from the objects still in the file.

Why an interrupted download breaks a PDF completely

A PDF keeps a cross-reference table: a list of every object in the file and the byte offset at which it starts. Readers use it to find the page list without scanning the whole document.

That table is at the end of the file. A download that stops part-way produces a file with most of its content and no table at all, and a reader that cannot locate the page list refuses the file entirely - even though nearly everything is sitting there.

What repair can and cannot do

It scans the file for objects and rebuilds the index from what it finds. Pages that transferred are recovered. Pages that never arrived are not, and cannot be by any tool. The page count in the result tells you which situation you are in.

What we recovered from truncated files

The same 40-page document, cut at different points.

Truncated atOpens normally?Repair recovers
100% (intact)Yesn/a
90%No36 of 40 pages
75%No30 of 40 pages
50%No19 of 40 pages
25%No9 of 40 pages
5%NoNothing - too little structure remains

Recovery is roughly proportional to how much of the file arrived, which is what you would expect from a format that writes pages in order.

The cases that are not damage

Two files that will not open are not broken at all, and treating them as broken wastes time.

An encrypted file asks for a password and refuses without one. That is the document working correctly. No repair tool will open it and none should claim to.

A file that is not a PDF cannot be opened as one. This happens when a download link returned an error page and the browser saved it with the expected filename. Opening it in a text editor is the quickest check - an HTML error page is immediately recognisable, and a real PDF begins with the characters %PDF.

Checking the first four bytes

Every PDF starts with %PDF followed by a version number. If the first line of the file is anything else, it is not a PDF and no PDF tool will help.

Opening the file in a text editor shows this immediately. Most of the file will be unreadable binary, which is expected; what matters is the first line.

Tools for each cause

Recoverable or not

The distinction that determines what to do next.

Usually recoverable

  • File is about the expected size
  • One reader opens it and another does not
  • It opened before and stopped opening
  • It came from an interrupted download

Not recoverable by repair

  • File is a few kilobytes when it should be megabytes
  • It asks for a password you do not have
  • It is an HTML error page with a .pdf extension
  • The download never started properly

After a repair

Check the page count against what you expected, and look at the last few pages. A repair that recovers 36 of 40 pages will not tell you which four are missing, and the missing ones are always at the end.

Treat a repaired document as provisional until you have confirmed the content you need is in it. A repair restores structure, not certainty.

Working through a file that will not open

  • Try a second reader before anything else
  • Check the file size against what it should be
  • Check whether it is asking for a password rather than failing
  • Confirm the file starts with %PDF
  • Re-download from the original source if you still can
  • Repair, then check the page count and the last pages

Questions and answers

Can a corrupted PDF be repaired?

Often, if the damage is structural. A rebuild reconstructs the index from the objects still in the file. It cannot recover content that never downloaded, and the recovered page count tells you which case you have.

Why does my PDF say it is damaged when it opened yesterday?

Most often a sync service replaced it with a partial copy, or the storage it lives on developed a fault. Check whether an earlier version is available before repairing.

My PDF asks for a password I never set. What is it?

The document was encrypted by whoever produced it - some school portals do this with a shared code. Ask the source. No tool can open it without the password.

The file is only 2 KB. Can that be fixed?

No. A 2 KB file contains essentially nothing. The download failed at the start rather than part-way through, and there is nothing to recover.

How this was checked. Reproduced by truncating real PDFs at several points and attempting recovery. The page counts recovered at each truncation point are the basis for the claims below.