Pagecraft

repair

Repair PDF

Rebuild a damaged document from whatever survives in it.

Reads
a PDF — application/pdf
Writes
one file — PDFs
Tool page
/repair-pdf

Example

Open a file another program wrote badly enough that readers refuse it.

Given

  • broken.pdf — a PDF whose cross-reference table is wrong of 3 pages

From code

            import { loadDocument, runOperation } from '@pagecraft/core';

const broken = await loadDocument({ bytes, name: 'broken.pdf' });

const [output] = await runOperation('repair', [broken]);
          

From a shell

            pagecraft repair broken.pdf
          

What comes back

One PDF of 3 pages.

This example is run by the test suite. If it stopped being true, the build would fail.

Options

This operation takes no options.

What it cannot do

  • Repair recovers what is still in the file. Content that never arrived — the tail of a download that stopped — is gone, and no tool can bring it back.
  • A page whose content cannot be decoded is kept and comes out blank, so the pages after it keep their numbers.
  • A rebuilt page tree is flat, and pages found by scanning are in the order the file stores them, which is usually but not always reading order.
  • A protected document is written back out in the clear. Protect it again if it needs a password.