PDF file format guide
What a PDF file contains, how it's structured, and why certain operations are easy while others aren't.
The basics
PDF (Portable Document Format) is a file format for representing documents in a way that looks identical on any device. It was standardized as ISO 32000 and is maintained by the PDF Association. Every modern operating system, web browser and mobile device can open a PDF.
What's inside a PDF
A PDF file is a structured binary document containing several kinds of objects:
- Page tree. Defines the pages and their order.
- Content streams. The instructions for drawing text, lines, images and shapes on each page.
- Fonts. Embedded font programs or references to standard fonts.
- Images. Raster data, usually JPEG or PNG-compressed.
- Annotations. Comments, links, form fields and markup as separate objects attached to pages.
- Metadata. Title, author, creation date, producer and custom fields.
- Outline / bookmarks. The navigation tree shown in a reader's sidebar.
- Encryption dictionary. Present if the document is password-protected.
Why editing in place is hard
The content stream is a sequence of drawing instructions like "move to (100, 200), set font to Helvetica 12, draw the text 'Hello'." There's no model of sentences or paragraphs — just positioned glyphs. Changing "Hello" to "Hi" requires:
- Finding the glyph group that spells "Hello"
- Removing those glyphs from the stream
- Inserting new glyphs with different advance widths
- Adjusting the positions of everything after them on that line
- Checking the line still fits within the column
Multiply that by every change you want to make. This is why Acrobat's "Edit Text" mode is fragile, why scanned PDFs can't be edited this way at all, and why most browser tools — including Omni PDF — work in additive mode instead.
What you can safely do to any PDF
- Copy pages into a new document (merge, split, extract)
- Rotate pages (metadata-only)
- Add new content on top (text, images, shapes, annotations)
- Add or remove annotations
- Add watermarks
- Re-render pages as images
- Change document metadata
What requires special handling
- Encrypted documents (password required)
- PDFs with broken object structures (parser recovery needed)
- PDFs over a few hundred megabytes (memory-bound)
- Documents using unusual compression or obscure filters
Glossary
- Content stream
- The instructions that draw a page.
- XObject
- A reusable object — usually an image or a form (a group of drawing instructions).
- AcroForm
- The interactive form layer, with fillable fields.
- Flatten
- Converting annotations or form fields into page content so they become permanent.
- Redaction
- Permanently removing content from a PDF. Requires rebuilding the page, not just covering.
- Linearization
- Reordering a PDF so the first page loads before the whole file is downloaded.