# uglytoad/pdfpig architecture

> Architecture diagram of the GitHub repository uglytoad/pdfpig, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-06). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/uglytoad/pdfpig
- Repository: https://github.com/uglytoad/pdfpig

## Overview

PdfPig is a .NET library for reading PDF content and performing limited PDF creation. The main reading workflow opens a document, accesses pages and letters, extracts words, segments text blocks, orders them, and can export layout data; creation builds pages and writes a new PDF. The graph also preserves documented encryption support, font handling, image support, and layout/export capabilities. Some subsystems are represented by their exact enclosing source directories because their implementing files are not included in the supplied tree; unverified connections are omitted.

Main entry points: [`src/UglyToad.PdfPig`](https://github.com/uglytoad/pdfpig/tree/master/src/UglyToad.PdfPig) (Document Access), [`src/UglyToad.PdfPig/Parser/PageContentParser.cs`](https://github.com/uglytoad/pdfpig/blob/master/src/UglyToad.PdfPig/Parser/PageContentParser.cs) (Page Content), [`src/UglyToad.PdfPig.Tokenization/StringTokenizer.cs`](https://github.com/uglytoad/pdfpig/blob/master/src/UglyToad.PdfPig.Tokenization/StringTokenizer.cs) (Tokenization), [`src/UglyToad.PdfPig/PdfFonts/Parser/Handlers/TrueTypeFontHandler.cs`](https://github.com/uglytoad/pdfpig/blob/master/src/UglyToad.PdfPig/PdfFonts/Parser/Handlers/TrueTypeFontHandler.cs) (Font Parsing)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_reading["PDF Reading"]
  node_document["Document Access<br/>[UglyToad.PdfPig]"]
  node_input["Byte Input<br/>[IInputBytes.cs]"]
  node_tokenizer["Tokenization<br/>[StringTokenizer.cs]"]
  node_tokens["PDF Tokens<br/>[DictionaryToken.cs]"]
  node_pagecontent["Page Content"]
end

subgraph group_interpretation["PDF Interpretation"]
  node_encryption["Decryption"]
  node_fonts["Font Parsing"]
  node_fontformats["Font Formats"]
  node_images["JPEG Handling<br/>[JpegHandler.cs]"]
end

subgraph group_analysis["Layout Analysis"]
  node_text["Text Extraction"]
  node_words["Word Extraction"]
  node_segments["Page Segmentation"]
  node_readingorder["Reading Order"]
  node_export["Layout Export<br/>[Export]"]
end

subgraph group_output["Creation and Export"]
  node_builder["PDF Builder<br/>[UglyToad.PdfPig]"]
  node_outputfile["PDF File"]
end

node_user(("Library User"))

node_user -->|"opens"| node_document
node_document -.->|"reads pages"| node_pagecontent
node_input -->|"supplies bytes"| node_tokenizer
node_tokenizer -->|"creates tokens"| node_tokens
node_document -.->|"supports passwords"| node_encryption
node_pagecontent -.->|"uses font parsing"| node_fonts
node_fonts -->|"parses font data"| node_fontformats
node_pagecontent -.->|"handles JPEG"| node_images
node_user -->|"extracts text"| node_text
node_user -->|"extracts words"| node_words
node_user -->|"segments words"| node_segments
node_segments -->|"orders blocks"| node_readingorder
node_user -.->|"exports layout"| node_export
node_user -->|"creates document"| node_builder
node_builder -->|"writes bytes"| node_outputfile

click node_document "https://github.com/uglytoad/pdfpig/tree/master/src/UglyToad.PdfPig"
click node_input "https://github.com/uglytoad/pdfpig/blob/master/src/UglyToad.PdfPig.Core/IInputBytes.cs"
click node_tokenizer "https://github.com/uglytoad/pdfpig/blob/master/src/UglyToad.PdfPig.Tokenization/StringTokenizer.cs"
click node_tokens "https://github.com/uglytoad/pdfpig/blob/master/src/UglyToad.PdfPig.Tokens/DictionaryToken.cs"
click node_pagecontent "https://github.com/uglytoad/pdfpig/blob/master/src/UglyToad.PdfPig/Parser/PageContentParser.cs"
click node_encryption "https://github.com/uglytoad/pdfpig/blob/master/src/UglyToad.PdfPig/Encryption/EncryptionHandler.cs"
click node_fonts "https://github.com/uglytoad/pdfpig/blob/master/src/UglyToad.PdfPig/PdfFonts/Parser/Handlers/TrueTypeFontHandler.cs"
click node_fontformats "https://github.com/uglytoad/pdfpig/tree/master/src/UglyToad.PdfPig.Fonts"
click node_images "https://github.com/uglytoad/pdfpig/blob/master/src/UglyToad.PdfPig/Images/JpegHandler.cs"
click node_text "https://github.com/uglytoad/pdfpig/blob/master/src/UglyToad.PdfPig.DocumentLayoutAnalysis/TextExtractor/ContentOrderTextExtractor.cs"
click node_words "https://github.com/uglytoad/pdfpig/blob/master/src/UglyToad.PdfPig.DocumentLayoutAnalysis/WordExtractor/NearestNeighbourWordExtractor.cs"
click node_segments "https://github.com/uglytoad/pdfpig/blob/master/src/UglyToad.PdfPig.DocumentLayoutAnalysis/PageSegmenter/DocstrumBoundingBoxes.cs"
click node_readingorder "https://github.com/uglytoad/pdfpig/blob/master/src/UglyToad.PdfPig.DocumentLayoutAnalysis/ReadingOrderDetector/UnsupervisedReadingOrderDetector.cs"
click node_export "https://github.com/uglytoad/pdfpig/tree/master/src/UglyToad.PdfPig.DocumentLayoutAnalysis/Export"
click node_builder "https://github.com/uglytoad/pdfpig/tree/master/src/UglyToad.PdfPig"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_document,node_input,node_tokenizer,node_tokens,node_pagecontent,node_user toneBlue
class node_encryption,node_fonts,node_fontformats,node_images toneAmber
class node_text,node_words,node_segments,node_readingorder,node_export toneMint
class node_builder,node_outputfile toneRose
```

## Components

### PDF Reading

- [Document Access](https://github.com/uglytoad/pdfpig/tree/master/src/UglyToad.PdfPig): `src/UglyToad.PdfPig`
- [Byte Input](https://github.com/uglytoad/pdfpig/blob/master/src/UglyToad.PdfPig.Core/IInputBytes.cs): `src/UglyToad.PdfPig.Core/IInputBytes.cs`
- [Tokenization](https://github.com/uglytoad/pdfpig/blob/master/src/UglyToad.PdfPig.Tokenization/StringTokenizer.cs): `src/UglyToad.PdfPig.Tokenization/StringTokenizer.cs`
- [PDF Tokens](https://github.com/uglytoad/pdfpig/blob/master/src/UglyToad.PdfPig.Tokens/DictionaryToken.cs): `src/UglyToad.PdfPig.Tokens/DictionaryToken.cs`
- [Page Content](https://github.com/uglytoad/pdfpig/blob/master/src/UglyToad.PdfPig/Parser/PageContentParser.cs): `src/UglyToad.PdfPig/Parser/PageContentParser.cs`

### PDF Interpretation

- [Decryption](https://github.com/uglytoad/pdfpig/blob/master/src/UglyToad.PdfPig/Encryption/EncryptionHandler.cs): `src/UglyToad.PdfPig/Encryption/EncryptionHandler.cs`
- [Font Parsing](https://github.com/uglytoad/pdfpig/blob/master/src/UglyToad.PdfPig/PdfFonts/Parser/Handlers/TrueTypeFontHandler.cs): `src/UglyToad.PdfPig/PdfFonts/Parser/Handlers/TrueTypeFontHandler.cs`
- [Font Formats](https://github.com/uglytoad/pdfpig/tree/master/src/UglyToad.PdfPig.Fonts): `src/UglyToad.PdfPig.Fonts`
- [JPEG Handling](https://github.com/uglytoad/pdfpig/blob/master/src/UglyToad.PdfPig/Images/JpegHandler.cs): `src/UglyToad.PdfPig/Images/JpegHandler.cs`

### Layout Analysis

- [Text Extraction](https://github.com/uglytoad/pdfpig/blob/master/src/UglyToad.PdfPig.DocumentLayoutAnalysis/TextExtractor/ContentOrderTextExtractor.cs): `src/UglyToad.PdfPig.DocumentLayoutAnalysis/TextExtractor/ContentOrderTextExtractor.cs`
- [Word Extraction](https://github.com/uglytoad/pdfpig/blob/master/src/UglyToad.PdfPig.DocumentLayoutAnalysis/WordExtractor/NearestNeighbourWordExtractor.cs): `src/UglyToad.PdfPig.DocumentLayoutAnalysis/WordExtractor/NearestNeighbourWordExtractor.cs`
- [Page Segmentation](https://github.com/uglytoad/pdfpig/blob/master/src/UglyToad.PdfPig.DocumentLayoutAnalysis/PageSegmenter/DocstrumBoundingBoxes.cs): `src/UglyToad.PdfPig.DocumentLayoutAnalysis/PageSegmenter/DocstrumBoundingBoxes.cs`
- [Reading Order](https://github.com/uglytoad/pdfpig/blob/master/src/UglyToad.PdfPig.DocumentLayoutAnalysis/ReadingOrderDetector/UnsupervisedReadingOrderDetector.cs): `src/UglyToad.PdfPig.DocumentLayoutAnalysis/ReadingOrderDetector/UnsupervisedReadingOrderDetector.cs`
- [Layout Export](https://github.com/uglytoad/pdfpig/tree/master/src/UglyToad.PdfPig.DocumentLayoutAnalysis/Export): `src/UglyToad.PdfPig.DocumentLayoutAnalysis/Export`

### Creation and Export

- [PDF Builder](https://github.com/uglytoad/pdfpig/tree/master/src/UglyToad.PdfPig): `src/UglyToad.PdfPig`
- **PDF File**

### Other components

- **Library User**

## Connections

- Library User → Document Access: opens (evidence: `README.md`)
- Document Access → Page Content: reads pages
- Byte Input → Tokenization: supplies bytes (evidence: `src/UglyToad.PdfPig.Tokenization/StringTokenizer.cs`)
- Tokenization → PDF Tokens: creates tokens (evidence: `src/UglyToad.PdfPig.Tokenization/StringTokenizer.cs`)
- Document Access → Decryption: supports passwords (evidence: `src/UglyToad.PdfPig/Encryption/EncryptionHandler.cs`)
- Page Content → Font Parsing: uses font parsing
- Font Parsing → Font Formats: parses font data (evidence: `src/UglyToad.PdfPig/PdfFonts/Parser/Handlers/TrueTypeFontHandler.cs`)
- Page Content → JPEG Handling: handles JPEG
- Library User → Text Extraction: extracts text (evidence: `README.md`)
- Library User → Word Extraction: extracts words (evidence: `README.md`)
- Library User → Page Segmentation: segments words (evidence: `README.md`)
- Page Segmentation → Reading Order: orders blocks (evidence: `README.md`)
- Library User → Layout Export: exports layout (evidence: `README.md`)
- Library User → PDF Builder: creates document (evidence: `README.md`)
- PDF Builder → PDF File: writes bytes (evidence: `README.md`)
