Inside a PDF File: Objects, Cross-References and Streams — The Anatomy That Explains Everything
Every weird PDF behaviour makes sense once you have seen the file's skeleton. A PDF is not a page image; it is a database of objects with a map. Four parts, in order.
The header
One line: %PDF-1.7. It declares the specification version. Everything after it is the document.
The objects
The body of the file: numbered objects that hold pages, content streams (the drawing instructions), fonts, images and metadata. Page 3 is not "a page" — it is a dictionary pointing at a content stream and a resource list. This object model is why a merge can copy pages without decoding them, and why text remains instructions rather than pixels.
The cross-reference table
A byte-offset map: which object starts where in the file. Readers use it to jump directly to what a page needs. When a file is edited incrementally, a new xref table is appended — the old data stays. This is why long-edited files bloat, and why redaction must actually delete objects rather than cover them: the "removed" text lives in an earlier revision.
The trailer
Points at the catalog object — the root of the page tree — and the location of the xref. The reader starts here, walks to the catalog, and renders.
Why this anatomy explains every tool behaviour
- Compression: the streams are already deflate-compressed; savings come from images and structure, not the text instructions.
- Splitting and merging: pages are objects — copying them between documents is trivial and lossless.
- Redaction: the secret is a text object; covering it draws another object on top. Removal means deleting the object.
- Incremental saves: the appended xref table is why "edited for years" files balloon.
Why the anatomy matters day to day
The file’s structure explains the two repairs people actually need. When a viewer says a file is corrupt, the break is usually in the cross-reference table — the index that maps every object to its byte position. Rebuilding that index from the surviving objects is exactly what Repair PDF does, and it recovers files that look completely dead. When a file is merely huge, the anatomy shows where the weight sits: streams hold the images, fonts, and page instructions, and duplicated objects from repeated edits pile up invisibly.
The structure also explains why some "saved" files keep growing: every edit can append a new version of an object rather than replacing the old one, and the xref simply points to the newest copy. Compress PDF removes those orphaned layers — which is why a file that grew for months often shrinks by half without any visible change.
Classic Cross-Reference Tables vs Compressed Object Streams (PDF 1.5+)
Early PDF revisions stored the cross-reference directory as plain ASCII text near the end of the file. Under that classic layout, every entry in the xref section is strictly 20 bytes long (nnnnnnnnnn ggggg n \r\n): a 10-digit byte offset measured from byte zero of %PDF-, a 5-digit generation counter for object reuse, an n (in-use) or f (free) status flag, and a two-byte end-of-line marker. That rigid 20-byte grid lets any viewer perform O(1) random-access seeks into a thousand-page manual without parsing the file from top to bottom, but it also leaves tens of thousands of small dictionary objects—annotations, font descriptors, bookmark nodes, and structure tags—sitting uncompressed in plain text.
Starting with PDF 1.5 (standardised in ISO 32000-1), writers introduced compressed object streams (/Type /ObjStm) alongside cross-reference streams (/Type /XRef). Instead of giving every small indirect object its own uncompressed obj ... endobj block, a writer packs dozens of non-stream dictionaries into a single FlateDecode-compressed container and replaces the ASCII xref table with a binary stream filtered through PNG row predictors (/Predictor 12). Because sequential byte offsets increase predictably, delta-encoding adjacent rows before deflate compression shrinks structural index overhead dramatically on tag-heavy documents and interactive forms.
A third structural layout—linearized PDF (often labelled Fast Web View)—reorders the object graph for streaming over HTTP. A linearized file places a dedicated /Linearized parameter dictionary and every object required to draw Page 1 right after the header, accompanied by a primary hint stream. When a browser opens a 40 MB technical specification hosted on a server that supports HTTP Range requests, it fetches the opening kilobytes, renders Page 1 immediately, and pulls later page subtrees on demand as the reader jumps through bookmarks.
Diagnosing Structural PDF Failures from Byte-Level Symptoms
Because every random-access lookup in a PDF relies on exact byte offsets from %PDF-, minor transport glitches break files in predictable ways. Understanding which structural layer failed tells you immediately whether a broken document is recoverable:
| Failure Symptom | Broken Anatomical Component | Structural Cause | Practical Fix |
|---|---|---|---|
| Viewer refuses to open file ("not a PDF or corrupted") | Header offset (%PDF-1.x) | Leading junk bytes—such as an HTML proxy warning or stray whitespace—prepend the file and shift every xref byte offset by N bytes. | Run Repair PDF, which strips leading garbage before %PDF- and recalculates clean offsets. |
File opens in some viewers or fails with "missing %%EOF" | Trailer & startxref pointer | Interrupted browser download or email gateway cutoff truncated the closing xref and trailer dictionary at the tail of the file. | Rebuild the object index from surviving obj markers on our server via Repair PDF. |
| 4-page form balloons to 18 MB after minor edits | Appended xref revisions & orphan streams | Incremental saves keep superseded font subsets, old images, and deleted page streams inside earlier %%EOF generations. | Rewrite the object graph into a single clean revision in your browser with Compress PDF. |
| Deleted cover or appendix still inflates file weight | Page tree vs unreferenced objects | Naive editors detach a page reference from /Kids in the /Pages tree without garbage-collecting its underlying image XObjects. | Delete unwanted sheets cleanly with Remove Pages, then strip leftover metadata via Edit PDF Metadata. |
One crucial boundary applies to any structural recovery: an index rebuild can only map objects whose bytes actually arrived on disk. When a network drop truncates a 10 MB scan at megabyte three, Repair PDF—which runs on our server using qpdf and Ghostscript over HTTPS and auto-deletes temporary copies within the hour—can reconstruct a valid /Pages tree and xref table for the surviving objects, whereas pages whose content streams never transferred must be re-exported from the source.
Frequently asked questions
What is inside a PDF file?
A header, a body of numbered objects (pages, content streams, fonts, images), a cross-reference table mapping byte offsets, and a trailer pointing at the document catalog.
Why can PDF text be selected and searched?
Because the text is real objects with unicode mappings — not pixels. Scans lack that layer until OCR writes one.
Why do edited PDF files get bigger over time?
Incremental saves append new revisions and cross-reference tables instead of rewriting the file — old data stays inside until the file is rewritten cleanly.