Guides Data & Encoding

How PDF Files Work

The structure of a PDF (header, objects, cross-reference table, trailer), a complete minimal file whose offsets were checked with pdfinfo, how pages and text are stored and how editing leaves traces.

Last reviewed:

AdSense Placeholder
Slot: header_reference_page
On this page

A PDF is a container of numbered objects, a table that says where each one starts, and a trailer that says where to begin reading. Pages are objects, fonts are objects, and the drawing instructions for each page are a stream of operators. Work with files using the Rotate PDF, PDF Metadata Editor and PDF to Text Converter; the term is defined in PDF (Portable Document Format).

The four parts of a file

  • Header: %PDF-1.4 names the version.
  • Body: numbered objects such as 3 0 obj ... endobj (object number, generation, then the content).
  • Cross-reference table (xref): for each object, the byte offset where it starts, so a reader can jump straight to it.
  • Trailer: names the root object (/Root) and ends with startxref, the offset of the table, then %%EOF.

A complete minimal PDF

This one-page file is complete. Its offsets are real: pdfinfo reads it as one 200 × 100 point page and pdftotext extracts "Hello PDF".

%PDF-1.4
1 0 obj
<< /Type /Catalog /Pages 2 0 R >>
endobj
2 0 obj
<< /Type /Pages /Kids [3 0 R] /Count 1 >>
endobj
3 0 obj
<< /Type /Page /Parent 2 0 R /MediaBox [0 0 200 100] /Contents 4 0 R /Resources << /Font << /F1 5 0 R >> >> >>
endobj
4 0 obj
<< /Length 39 >>
stream
BT /F1 18 Tf 20 50 Td (Hello PDF) Tj ET
endstream
endobj
5 0 obj
<< /Type /Font /Subtype /Type1 /BaseFont /Helvetica >>
endobj
xref
0 6
0000000000 65535 f 
0000000009 00000 n 
0000000058 00000 n 
0000000115 00000 n 
0000000241 00000 n 
0000000330 00000 n 
trailer
<< /Size 6 /Root 1 0 R >>
startxref
400
%%EOF

How the pieces fit

  • The /Root catalog points to the page tree (/Pages), which lists the pages (/Kids).
  • Each page has a /MediaBox (size in points; 72 points = 1 inch) and /Contents, a stream such as BT ... ET that sets a font, moves to a position and shows text.
  • Resources like fonts are referenced by name (/F1) and defined elsewhere.
  • Real files compress streams (/Filter /FlateDecode) and store many objects together in object streams to save space.
  • Metadata lives in the /Info dictionary and optionally in XMP; see and change it with the PDF Metadata Editor.

Why it matters

  • Edits can be saved as an incremental update: new objects and a new xref are appended, and the old ones stay in the file. Deleted or redacted content may remain recoverable.
  • Text extraction depends on how a font maps glyphs to characters; scanned pages hold only images and need OCR.
  • A corrupt xref can often be rebuilt by scanning for obj markers, which is how many readers repair damaged files.
  • To check a document for hidden changes, see How to Check a PDF for Hidden Changes.

Try these tools

See also

  • Glossary PDF (Portable Document Format)
    PDF is a file format for documents that look the same on every device, bundling text, fonts, images and layout into one file.
  • Glossary Metadata
    Metadata is data about data: the hidden or secondary information a file carries about itself, such as its author, creation date.
  • Glossary OCR (optical character recognition)
    OCR converts text in an image or scan into editable, searchable text.
  • Glossary Watermark
    A watermark is text or a logo laid over an image or document to show ownership or discourage reuse.
  • How-to How to Merge, Split and Reorder a PDF
    Combine several PDFs into one, pull out the pages you need, reorder or rotate them, and add page numbers.
  • How-to How to Check a PDF for Hidden Changes
    Find out whether a PDF was edited after it was created or signed: incremental saves, changed text between revisions.
  • Guide How File Signatures (Magic Bytes) Work
    How the first bytes of a file identify its real type, a table of common signatures verified against real files.

Frequently Asked Questions

A PDF stores positioned drawing instructions, not flowing text. Words are placed glyph by glyph, with no paragraphs, so editors have to reconstruct lines and fonts and often cannot.

AdSense Placeholder
Slot: footer_leaderboard