# hoehermann/pypdf_strreplace architecture

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

- Interactive diagram: https://gitdiagram.com/hoehermann/pypdf_strreplace
- Repository: https://github.com/hoehermann/pypdf_strreplace

## Overview

PyPDF Text Search and Replace is a command-line tool for inspecting and editing text in PDF content streams, with an optional GUI for examining operations. The main workflow reads pages, builds per-page font context, extracts searchable text, schedules and applies replacements or deletions, then writes the modified PDF. Font encoding and optional TrueType font support underpin edits; the debug UI is a separate optional capability. Relationships are based on the README and shown source; unsampled implementation details are not inferred.

Main entry points: [`pypdf_strreplace/main.py`](https://github.com/hoehermann/pypdf_strreplace/blob/master/pypdf_strreplace/main.py) (CLI and page loop), [`pypdf_strreplace/context.py`](https://github.com/hoehermann/pypdf_strreplace/blob/master/pypdf_strreplace/context.py) (Page font context), [`pypdf_strreplace/content.py`](https://github.com/hoehermann/pypdf_strreplace/blob/master/pypdf_strreplace/content.py) (Stream text processing), [`pypdf_strreplace/operations.py`](https://github.com/hoehermann/pypdf_strreplace/blob/master/pypdf_strreplace/operations.py) (PDF text operations)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_workflow["PDF workflow"]
  node_cli["CLI and page loop<br/>[main.py]"]
  node_pdfio["PyPDF reader/writer"]
end

subgraph group_text["Text processing"]
  node_stream["Stream text processing<br/>[content.py]"]
  node_operations["PDF text operations<br/>[operations.py]"]
  node_changes["Edit actions<br/>[changes.py]"]
end

subgraph group_fonts["Font handling"]
  node_pagefonts["Page font context<br/>[context.py]"]
  node_codec["Font codecs<br/>[codec.py]"]
  node_fontrepo["TrueType font repository<br/>[font.py]"]
end

subgraph group_debug["Debug interface"]
  node_debugger["Debug setup and display<br/>[debug.py]"]
  node_gui["Operation tree UI<br/>[gui.py]"]
end

node_user(("User"))
node_pdf["PDF input"]
node_output["Modified PDF"]

node_user -->|"runs"| node_cli
node_pdf -->|"provides input"| node_cli
node_cli -->|"reads and writes"| node_pdfio
node_cli -->|"builds context"| node_pagefonts
node_pagefonts -->|"creates codecs"| node_codec
node_cli -->|"processes contents"| node_stream
node_stream -->|"builds operations"| node_operations
node_operations -->|"uses context"| node_pagefonts
node_stream -->|"applies changes"| node_changes
node_cli -.->|"loads optional fonts"| node_fontrepo
node_pagefonts -.->|"gets font widths"| node_fontrepo
node_cli -->|"initializes optionally"| node_debugger
node_debugger -->|"creates interface"| node_gui
node_pdfio -->|"writes result"| node_output

click node_cli "https://github.com/hoehermann/pypdf_strreplace/blob/master/pypdf_strreplace/main.py"
click node_pagefonts "https://github.com/hoehermann/pypdf_strreplace/blob/master/pypdf_strreplace/context.py"
click node_codec "https://github.com/hoehermann/pypdf_strreplace/blob/master/pypdf_strreplace/codec.py"
click node_fontrepo "https://github.com/hoehermann/pypdf_strreplace/blob/master/pypdf_strreplace/font.py"
click node_stream "https://github.com/hoehermann/pypdf_strreplace/blob/master/pypdf_strreplace/content.py"
click node_operations "https://github.com/hoehermann/pypdf_strreplace/blob/master/pypdf_strreplace/operations.py"
click node_changes "https://github.com/hoehermann/pypdf_strreplace/blob/master/pypdf_strreplace/changes.py"
click node_debugger "https://github.com/hoehermann/pypdf_strreplace/blob/master/pypdf_strreplace/debug.py"
click node_gui "https://github.com/hoehermann/pypdf_strreplace/blob/master/pypdf_strreplace/gui.py"

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_cli,node_pdfio,node_user toneBlue
class node_stream,node_operations,node_changes toneAmber
class node_pagefonts,node_codec,node_fontrepo toneMint
class node_debugger,node_gui toneRose
class node_pdf,node_output toneIndigo
```

## Components

### PDF workflow

- [CLI and page loop](https://github.com/hoehermann/pypdf_strreplace/blob/master/pypdf_strreplace/main.py): `pypdf_strreplace/main.py`
- **PyPDF reader/writer**

### Text processing

- [Stream text processing](https://github.com/hoehermann/pypdf_strreplace/blob/master/pypdf_strreplace/content.py): `pypdf_strreplace/content.py`
- [PDF text operations](https://github.com/hoehermann/pypdf_strreplace/blob/master/pypdf_strreplace/operations.py): `pypdf_strreplace/operations.py`
- [Edit actions](https://github.com/hoehermann/pypdf_strreplace/blob/master/pypdf_strreplace/changes.py): `pypdf_strreplace/changes.py`

### Font handling

- [Page font context](https://github.com/hoehermann/pypdf_strreplace/blob/master/pypdf_strreplace/context.py): `pypdf_strreplace/context.py`
- [Font codecs](https://github.com/hoehermann/pypdf_strreplace/blob/master/pypdf_strreplace/codec.py): `pypdf_strreplace/codec.py`
- [TrueType font repository](https://github.com/hoehermann/pypdf_strreplace/blob/master/pypdf_strreplace/font.py): `pypdf_strreplace/font.py`

### Debug interface

- [Debug setup and display](https://github.com/hoehermann/pypdf_strreplace/blob/master/pypdf_strreplace/debug.py): `pypdf_strreplace/debug.py`
- [Operation tree UI](https://github.com/hoehermann/pypdf_strreplace/blob/master/pypdf_strreplace/gui.py): `pypdf_strreplace/gui.py`

### Other components

- **User**
- **PDF input**
- **Modified PDF**

## Connections

- User → CLI and page loop: runs (evidence: `README.md`)
- PDF input → CLI and page loop: provides input (evidence: `pypdf_strreplace/main.py`)
- CLI and page loop → PyPDF reader/writer: reads and writes (evidence: `pypdf_strreplace/main.py`)
- CLI and page loop → Page font context: builds context (evidence: `pypdf_strreplace/main.py`)
- Page font context → Font codecs: creates codecs (evidence: `pypdf_strreplace/context.py`)
- CLI and page loop → Stream text processing: processes contents (evidence: `pypdf_strreplace/main.py`)
- Stream text processing → PDF text operations: builds operations (evidence: `pypdf_strreplace/content.py`)
- PDF text operations → Page font context: uses context (evidence: `pypdf_strreplace/operations.py`)
- Stream text processing → Edit actions: applies changes (evidence: `pypdf_strreplace/content.py`)
- CLI and page loop → TrueType font repository: loads optional fonts (evidence: `pypdf_strreplace/main.py`)
- Page font context → TrueType font repository: gets font widths (evidence: `pypdf_strreplace/context.py`)
- CLI and page loop → Debug setup and display: initializes optionally (evidence: `pypdf_strreplace/main.py`)
- Debug setup and display → Operation tree UI: creates interface (evidence: `pypdf_strreplace/debug.py`)
- PyPDF reader/writer → Modified PDF: writes result
