Skip to main content

Module linearization

Module linearization 

Source
Expand description

§Linearization (Fast Web View) detection — ISO 32000-1 Annex F

Detection only. pdfcer does not write linearized files, and this module deliberately implements nothing that would be needed to: no hint-table parsing (Annex F.4), no part-ordering validation (F.3.5, F.3.7–F.3.10). Producing a linearized file needs all of that; recognizing one, and stating honestly what a save does to it, needs only Table F.1’s parameter dictionary. Spec source: iso32000__annex__f.md in the PDF-spec RAG.

§Why pdfcer detects something it cannot produce

Decision 007 W5 and R36. An incremental save appends past the first-page cross-reference table and the hint streams, so the linearization is stale afterwards. F.1 is normative and blunt about it: “Incremental update shall still be permitted, but the resulting PDF is no longer linearized and subsequently shall be treated as ordinary PDF.”

That is spec-sanctioned and unavoidable — but it is also an observable property change the operator did not ask for (the file opens more slowly over a network afterwards). CLAUDE.md rule 4, “fuzzy, never sneaky”, makes silently degrading it the wrong behavior. So: detect on load, name it, warn on save.

§What this module refuses to do, and why

  • It never strips a stale /Linearized dictionary. Removing it would be a normalization (R33) and Annex G.7’s reader-side revalidation path depends on the dictionary still being there.
  • It never patches L. L is not the property — the object ordering and hint validity are. A file whose L was “fixed” after an append claims to be linearized while its hints point into a stale layout, which is strictly worse for a network reader than an honestly de-linearized file. (It is also impossible in an append-only save, since L lives at the front.)

§The detection recipe (F.3.3 + Table F.1)

  1. The parameter dictionary “shall be entirely contained within the first 1024 bytes of the PDF file” — so the scan is bounded, and that bound exists precisely so a reader can decide cheaply.
  2. It is “the first object in the body of the file”, an indirect dictionary, and “all values in this dictionary shall be direct objects” — so detection needs no cross-reference table and can run before the xref is parsed at all.
  3. /Linearized present ⇒ candidate.
  4. L (required) “shall be exactly equal to the actual length of the PDF file. A mismatch indicates that the file is not linearized and shall be treated as ordinary PDF.” This is the liveness check, and it is why step 3 alone is not enough: a stale /Linearized dictionary survives any append.

Enums§

Linearization
What Annex F detection concluded about a loaded file.

Constants§

LINEARIZATION_SCAN_WINDOW
How far into the file the linearization parameter dictionary is searched for.

Functions§

detect
Detect Annex F linearization in buf.