Pagecraft

linearize

Linearize PDF

Reorder a document so a reader can show page one before the rest arrives.

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

Example

Arrange a document so a browser can show page one before it has the rest.

Given

  • report.pdf — an ordinary PDF of 6 pages

From code

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

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

const [output] = await runOperation('linearize', [report]);
          

From a shell

            pagecraft linearize report.pdf
          

What comes back

One PDF of 6 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

  • Pagecraft reorders the objects so that page one and everything it draws with come first. It does not write the hint tables a fully linearized file carries, so a reader that insists on those will fall back to reading the whole file.
  • The difference is only visible over a network, and only from a server that answers byte-range requests. Opening the file from a disk is exactly as fast either way.
  • Nothing about the document changes: same pages, same order, same size on paper.