Introduction
This is PDF from version 1.5, of Acrobat 6.0 in 2003, to PDF 2.0, the version in use today: the files written by Acrobat 6.0 and later and by nearly every program that writes PDF now. A PDF holds fixed pages of text, vector graphics and images, with the fonts it needs, and can carry links, forms, annotations, digital signatures, attachments, layers, 3D models and accessibility tags. PDF 1.7 became the international standard ISO 32000-1 in 2008, and PDF 2.0 is ISO 32000-2, first published in 2017, with a second edition in 2020. Documents are made and read with Adobe Acrobat and many other programs.
PDF 1.5 changed how objects are stored and found. Objects may be packed, many at a time, inside a compressed object stream, and the cross-reference table may be replaced by a cross-reference stream: a compressed binary index that can point into those object streams. A reader of PDF 1.4 cannot find such objects, so this is a separate format from PDF 1.0 to 1.4. Hybrid files keep a plain table as well, for older readers. Versions 1.6, 1.7 and 2.0 add to this format and deprecate parts of it, but do not change these structures, so they belong to it. PDF 1.6 brought AES encryption, and Adobe’s extensions to 1.7, then PDF 2.0, AES with 256-bit keys.
A .pdf file dropped on any page opens in the explorer, which shows its
objects, unpacks object streams, decodes cross-reference streams, walks the page
tree and decodes the other streams, with fonts, images and other embedded files
opening in their own viewers. It does not draw the pages.
Structure
A file is a header line, a body of objects, a cross-reference section and a
trailer. The cross-reference section is either a plain xref table
with a trailer dictionary, or a cross-reference stream whose
dictionary is the trailer. startxref at the end gives its offset
either way.
0Header%PDF-1.5to%PDF-1.7, or%PDF-2.0, and a binary commenttwo lines…Body indirect objects and object streams that hold more objectsmost of the file…Cross-reference stream/Type /XRef: binary entries for every object, and the trailer’s keys; or an xref table andtrailera few bytes an object…startxref the offset of the cross-reference section, and%%EOFthree lines
%%EOFA real file
A small PDF 1.7 file of 3,527 bytes. Its header and binary comment come first, then object 3:
00000000 25 50 44 46 2D 31 2E 37 0A 25 E4 E3 CF D2 0A 33 %PDF-1.7.%.....3
00000010 20 30 20 6F 62 6A 0A 3C 3C 2F 4C 65 6E 67 74 68 0 obj.<</Length
%PDF-1.7, a comment of four bytes above 127, and 3 0 obj at offset 15Five of its objects are packed in object stream 10, and the file ends with a cross-reference stream, object 16, instead of a table:
10 0 obj
<</Length 15 0 R/Filter/FlateDecode/Type/ObjStm/N 5/First 27>>
…
16 0 obj
<</Filter/FlateDecode/Type/XRef/W[1 2 2]/Size 17/Root 14 0 R/Info 11 0 R
/ID[<57A984D8D8017E7021C18DB41CC7EE07><57A984D8D8017E7021C18DB41CC7EE07>]
/DecodeParms<</Columns 5/Predictor 12>>/Length 87 >>
stream
…87 bytes…
endstream
endobj
startxref
3180
%%EOF
From the trailer to a page
The trailer’s Root, here in the cross-reference stream’s dictionary,
is the catalog,
whose Pages is the root of the
page tree.
Each page has a MediaBox, its Resources and its
Contents, a content
stream of drawing operators. The page dictionaries themselves may be inside an
object stream, so a reader finds them through the cross-reference stream’s
type 2 entries.
Reference pages
- File structure – the header, binary comment, body, cross-reference section, trailer,
%%EOF, incremental updates and hybrid files - Objects and syntax – the eight object types, strings, names, indirect objects and references, text strings and dates
- Streams and filters – the stream dictionary, every filter of these versions, Crypt filters and the predictors
- Cross-reference and trailer – xref tables, cross-reference streams and their entry types, object streams, hybrid-reference files and the trailer
- Document structure – the catalog, page tree, pages, resources, name and number trees, outlines, destinations, structure, optional content and collections
- Content streams – all 73 operators with their operands and the version that added each
- Graphics – coordinate spaces, colour spaces, patterns, shadings, functions, graphics state and transparency
- Fonts – Type 1, TrueType, Type 3, Type 0 and CIDFonts, encodings, CMaps, ToUnicode, descriptors and embedding, OpenType included
- Images – image XObjects, Decode arrays, masks and soft masks, JPEG 2000 and inline images
- Interactive features – annotations, actions, JavaScript, forms, signatures, embedded files and multimedia
- Metadata – the document information dictionary, XMP metadata streams and what PDF 2.0 changes
- Encryption – crypt filters, AES-128 and AES-256, the standard security handler revisions 2 to 6, permissions and public-key handlers
- Linearization – fast web view: the parameter dictionary, the order of parts, the hint tables, and object streams
- Versions – 1.5, 1.6, 1.7, Adobe’s extension levels, 2.0, and PDF/A, PDF/X, PDF/UA and PDF/E
Telling it apart
A PDF starts with %PDF- (25 50 44 46 2D) and a version.
A file is in this format when its header says 1.5, 1.6, 1.7 or 2.0, or when,
whatever its header says, it holds a cross-reference stream
(/Type /XRef), an XRefStm entry in a trailer, or an
object stream (/Type /ObjStm). Some programs write a 1.4 header and
then add a cross-reference stream when they update the file; such a file is read
as this format.
A file with a header of 1.0 to 1.4 that has only plain tables and no object
streams is the older format, PDF 1.0 to 1.4. The catalog’s Version
entry can raise the version above the header’s, and PDF 2.0 files written by
updating older ones often do so.
Some files with other extensions are PDF inside. Adobe Illustrator’s
.ai files from Illustrator 9 on are PDF files that also carry
Illustrator’s own data, and open in a PDF reader as their artwork.
Variants
- Portable Document Format, PDF 1.0 to 1.4 – objects at their own offsets, indexed by a plain-text cross-reference table; RC4 encryption
- Portable Document Format, PDF 1.5 to 2.0 – objects can be packed in object streams and indexed by cross-reference streams; AES encryption
Links
Software
- Adobe Acrobat Reader – Adobe’s free PDF viewer, with forms and comments (Windows, macOS, mobile)
- PDF.js – the viewer built into Firefox (web browsers)
- SumatraPDF – small, fast free viewer (Windows)
- Okular – KDE’s document viewer (Linux, Windows)
- LibreOffice Draw – free drawing program that can edit PDF pages (Windows, macOS, Linux)
- Ghostscript – interpreter that renders, converts and compresses PDF (Windows, macOS, Linux)
- qpdf – command-line tool that shows a file’s structure, unpacks object streams, decrypts and repairs PDF (Windows, macOS, Linux)
Developers
- PDF.js – library that parses and renders PDF (JavaScript)
- pypdf – library that reads, splits, merges and writes PDF (Python)
- Apache PDFBox – library for reading and creating PDF (Java)
- qpdf – library for inspecting and rewriting PDF structure (C++)
- MuPDF – library and viewer for rendering PDF (C)
Reference
- ISO 32000-1:2008 – PDF 1.7 as an ISO standard, in Adobe’s copy (PDF)
- ISO 32000 (PDF) – the PDF Association’s page on the standard, with free access to PDF 2.0, ISO 32000-2:2020
- PDF issues – the PDF Association’s list of errata and clarifications to ISO 32000-2
- PDF Reference, fourth edition – Adobe’s description of PDF 1.5 (PDF)
- PDF Reference, fifth edition – PDF 1.6 (PDF)
- PDF Reference, sixth edition – PDF 1.7, before it became ISO 32000-1 (PDF)
- Arlington PDF Model – the PDF Association’s machine-readable model of every PDF 2.0 object, with the version each key was added and deprecated in