Leanpub Header

Skip to main content

Mastering PDF Parsing

Building a PDF Reader from the ISO 32000-2 Specification

This book is 100% completeLast updated on 2026-07-28

Go beyond using PDF libraries and learn how the format really works. This book walks you through building a complete PDF reader from scratch using the ISO 32000-2 specification, with clear explanations, written in C++ code and a parser that handles real-world PDF files from the ground up.

Minimum price

$29.00

$39.00

You pay

Author earns

$

Also available for 2 book credits with a Reader Membership

PDF
EPUB
WEB
APP
222
Pages
About

About

About the Book

This book teaches you how the PDF file format works by progressively designing and implementing a complete, standards-compliant PDF reader and parser from scratch based on the latest ISO 32000-2 specification. Beginning with the history and architecture of PDF, each chapter explains a core component of the format in technical depth while extending a working C++ implementation. By the final chapter, you will have built a fully functional PDF parser capable of opening, validating, navigating, and extracting information from real-world PDF documents without relying on any third-party PDF libraries. The code explanations are rigorous, and every claim traces back to the specification itself. This is both a deep exploration of the PDF 2.0 standard and a complete implementation guide for experienced software developers.

Author

About the Author

Steve Publications

Steve is a technology professional with more than 20 years of experience in software development, server infrastructure, cybersecurity, vulnerability research and reverse engineering. Throughout his career, he has designed, secured, analyzed and tested complex software and infrastructure, with a particular focus on understanding how systems fail and how they can be made more secure.

Outside of work, Steve enjoys sharing knowledge with the technology community. He collaborates with researchers, industry experts and technology professionals to write practical books covering software development, cybersecurity, cloud computing, networking, DevOps, artificial intelligence and enterprise technologies. His books focus on practical learning through clear explanations, real-world examples and hands-on exercises. With more than two decades of industry experience, his goal is to help IT professionals, students and technology enthusiasts build useful skills and stay current in a rapidly changing industry.

We believe readers deserve to know how our books are created. Most of our authors are not native English speakers, so we use AI to help translate, proofread manuscripts, fix grammar, improve sentence structure and make technical explanations easier to read. AI is used as an editing tool only. It does not replace the research, technical knowledge or hands-on experience behind our books. Some of our authors also prefer to remain anonymous for privacy or professional reasons. In those cases, we publish their work under a different name. The author's name may be different, but the quality of the content and our review process remain the same.

Every book is written, reviewed and maintained by experienced technology professionals, with contributions from our private technical community of more than 420 engineers and researchers from Ukraine, Belarus and Russia. We spend far more time validating technical accuracy and keeping our content up to date than generating text. We are always interested in working with experienced professionals who have deep expertise in a particular technology or domain. If you would like to publish a book with us or help review an existing manuscript, we'd love to hear from you. Send us a message describing your area of expertise. We are especially interested in niche technologies, specialized skills and emerging topics that are underrepresented in existing technical literature.

If you look through the contents of our books, you'll see practical examples, detailed explanations and material that is regularly updated. Our goal is to publish books that professionals can actually rely on, not low-effort AI-generated content. If you ever feel that one of our books does not meet that standard, Leanpub offers a 60-day money-back guarantee. Feel free to request a refund if you are not satisfied with your purchase.

Contents

Table of Contents

Building a PDF Reader from the ISO 32000-2 Specification

Introduction: Why Build a PDF Parser?

  1. The Ubiquity and Hidden Complexity of PDF
  2. What This Book Will Build
  3. How to Read This Book: Code Structure and Conventions
  4. Getting Started: Project Setup and Toolchain

Chapter 1: History, Design Goals, and Architecture of PDF

  1. PostScript Heritage and the Birth of Acrobat
  2. Design Principles: Device Independence, Portability, Interactivity
  3. Version Timeline from PDF 1.0 to PDF 2.0
  4. The Object Model: A Foundation for Everything
  5. File Structure at a Glance: Headers, Bodies, Cross-References, Trailers
  6. Building the File I/O Layer

Chapter 2: Lexical Structure and the Tokenizer

  1. The PDF Character Set and Whitespace Rules
  2. Delimiters, Brackets, and Parentheses
  3. Numeric Tokens: Integers and Real Numbers
  4. Names, Literal Strings, Hexadecimal Strings, Booleans, Null
  5. Comments and Escaping Rules
  6. Building the Tokenizer: Complete Implementation

Chapter 3: Direct Objects and Recursive-Descent Parsing

  1. The Parser Architecture: From Tokens to Object Trees
  2. Parsing Numbers and Simple Values
  3. Parsing Literals Strings with Escape Sequences
  4. Parsing Hexadecimal Strings and Length Validation
  5. Parsing Names and Key Resolution
  6. Parsing Dictionaries: Keys, Values, and Nested Structures
  7. Parsing Arrays and Recursive Descent Patterns
  8. Putting It All Together: A Simple Test

Chapter 4: Indirect Objects, Object Numbering, and Streams

  1. Why Indirect Objects Matter: Referencing and Random Access
  2. The obj-endobj Syntax and Object Numbers
  3. Stream Objects: Headers, Lengths, and Data Boundaries
  4. Basic Stream Parsing and the /Length Entry
  5. Building an Object Table for Indirect References
  6. Handling Cross-References Between Objects

Chapter 5: Cross-Reference Tables, Streams, and the Trailer

  1. The %%EOF Marker and Backward Search
  2. The Trailer Dictionary: Root, Size, Encrypt, Prev
  3. Traditional Cross-Reference Tables: Entry Formats and Types
  4. Parsing the xref Section Byte by Byte
  5. Cross-Reference Streams (PDF 1.5+): W, Index, Filter Entries
  6. Incremental Updates and Multiple xref Sections

Chapter 6: Stream Filters and Decompression

  1. The Filter Chain: Sequential Decompression
  2. ASCIIHexDecode and ASCII85Decode Implementations
  3. LZWDecode: TIFF Class F Algorithm Details
  4. FlateDecode: zlib Integration and Raw Deflate
  5. RunLengthDecode and CCITTFaxDecode
  6. DCTDecode, JBIG2Decode, JPXDecode Overview
  7. The Crypt Filter and Encryption Basics
  8. Putting It All Together: Filter Chain Application

Chapter 7: Document Catalog and Page Tree Navigation

  1. The Catalog Dictionary: Type, Pages, Names, Outlines
  2. The Pages Object: Kids, Count, Parent Relationships
  3. Traversing the Page Tree Recursively
  4. Page Objects: MediaBox, CropBox, Rotate, Resources
  5. Resource Dictionaries: Fonts, XObjects, ColorSpaces, Patterns
  6. Building a Document Navigation API

Chapter 8: Content Streams and Graphics Operators

  1. Content Stream Syntax and Operator Tokens
  2. The Current Transformation Matrix (CTM)
  3. Path Construction Operators: moveto, lineto, curveto
  4. Path Painting: Stroke, Fill, Clip Operations
  5. Text State and Positioning Operators
  6. Graphics State Saving and Restoring: q and Q
  7. Marked Content and Tagged PDF Basics
  8. Parsing Content Streams
  9. Inline Images in Content Streams

Chapter 9: Coordinate Systems and Page Geometry

  1. User Space vs. Device Space
  2. The Transformation Matrix Pipeline
  3. Clipping Paths and the Clip Operator Family
  4. Tiling Patterns and Pattern Paint
  5. Shadings: Axial, Radial, and Coons Mesh
  6. Page Boxes: MediaBox, CropBox, BleedBox, TrimBox, ArtBox

Chapter 10: Text Rendering and Fonts

  1. The Text Rendering Model: ShowText Operators
  2. Font Dictionaries: Type, Subtype, Encoding
  3. Standard Type 1 Fonts and Built-in Encodings
  4. TrueType and OpenType Font Embedding
  5. CID Fonts and CMap Parsing
  6. Character Spacing, Word Spacing, Leading
  7. Extracting Text from Content Streams

Chapter 11: Images and Color Spaces

  1. Image XObjects: Width, Height, BitsPerComponent
  2. Image Masking and Soft Masks
  3. Device Color Spaces: RGB, CMYK, Gray
  4. ICC-Based Color Spaces and Profile Handling
  5. Special Color Spaces: Separation, DeviceN, Indexed
  6. Loading and Decoding Image Data

Chapter 12: Annotations, Links, and Interactivity

  1. Annotation Dictionaries: Type, Subtype, Rect
  2. Link Annotations and URI Actions
  3. Text and Highlight Annotations
  4. Destination Types: XYZ, Fit, FitH, FitV, FitR, FitB
  5. Outlines (Bookmarks): Tree Structure and Navigation
  6. Named Destinations and the Names Dictionary

Chapter 13: Forms, AcroForms, and Interactive Fields

  1. The AcroForm Dictionary and Field Hierarchy
  2. Field Types: Text, Button, Choice, Signature
  3. Field Appearance Streams and Rendering
  4. Field States: ReadOnly, Required, Export Values
  5. Radio Button Groups and Checkboxes
  6. Form Submission Actions

Chapter 14: Security, Encryption, and Digital Signatures

  1. The Encrypt Dictionary and Security Handlers
  2. Standard Security Handler: User/Owner Passwords
  3. RC4 Encryption Algorithm Implementation
  4. AES Encryption (AESV2, AESV3)
  5. Integrating Encryption into the Core Architecture
  6. Permission Flags and Document Restrictions
  7. Digital Signatures: Byte Range, Certificate Chains

Chapter 15: Advanced Features in PDF 2.0

  1. What Changed in PDF 2.0
  2. Enhanced Transparency and Blending
  3. Improved ICC Color Management
  4. New Filter Capabilities and Requirements
  5. Structural Improvements: Object Streams Refinements
  6. Removed Features: XFA Deprecation
  7. UTF-8 Support and Text String Improvements
  8. Portfolio and Collection Enhancements

Chapter 16: Robustness, Performance, and Real-World Issues

  1. Malformed Document Recovery Strategies
  2. Fuzz Testing and Security Hardening
  3. Memory Management: Caching Indirect Objects
  4. Lazy Loading and On-Demand Decoding
  5. Random Access Patterns and File I/O Optimization
  6. Interoperability Issues Across PDF Generators

Conclusion: A Complete Parser, An Open Format

  1. What We Built: The Complete Implementation
  2. Lessons from Building a Standards-Compliant Parser
  3. Extending the Reader: Rendering and Beyond
  4. The Future of PDF in a Digital World

References

Get the free sample chapters

Click the buttons to get the free sample in PDF or EPUB, or read the sample online here

The Leanpub 60 Day 100% Happiness Guarantee

Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.

See full terms...

Earn $8 on a $10 Purchase, and $16 on a $20 Purchase

We pay 80% royalties on purchases of $7.99 or more, and 80% royalties minus a 50 cent flat fee on purchases between $0.99 and $7.98. You earn $8 on a $10 sale, and $16 on a $20 sale. So, if we sell 5000 non-refunded copies of your book for $20, you'll earn $80,000.

(Yes, some authors have already earned much more than that on Leanpub.)

In fact, authors have earned over $15 million writing, publishing and selling on Leanpub.

Learn more about writing on Leanpub

Free Updates. DRM Free.

If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).

Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.

Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.

Learn more about Leanpub's ebook formats and where to read them

Write and Publish on Leanpub

You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!

Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.

Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF and/or EPUB files and then publish with one click!) It really is that easy.

Learn more about writing on Leanpub