# kwong012/pdftexteditor architecture

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

- Interactive diagram: https://gitdiagram.com/kwong012/pdftexteditor
- Repository: https://github.com/kwong012/pdftexteditor

## Overview

PDFTextEditor is a desktop and command-line tool for editing selectable text in PDFs while preserving its appearance. The main workflow is: open a PDF, select text, draft a replacement and preview it, add it to the change list, then export the edited PDF. The shared core locates targets, resolves drawing settings and applies replacements; font discovery supports matching the original typeface. GUI internals are only partially sampled, so some documented GUI-to-core wiring is shown at subsystem level.

Main entry points: [`pdf_edit_core.py`](https://github.com/kwong012/pdftexteditor/blob/compare-preview/pdf_edit_core.py) (Replace and redraw), [`pdf_editor_gui.py`](https://github.com/kwong012/pdftexteditor/blob/compare-preview/pdf_editor_gui.py) (Desktop editor), [`edit_pdf.py`](https://github.com/kwong012/pdftexteditor/blob/compare-preview/edit_pdf.py) (CLI entry point), [`config.example.json`](https://github.com/kwong012/pdftexteditor/blob/compare-preview/config.example.json) (Shared JSON config)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interfaces["User interfaces"]
  node_gui["Desktop editor<br/>[pdf_editor_gui.py]"]
  node_gui_preview["Preview and selection<br/>[pdf_editor_gui.py]"]
  node_gui_rules["Change list<br/>[pdf_editor_gui.py]"]
  node_cli["CLI entry point<br/>[edit_pdf.py]"]
  node_config["Shared JSON config"]
end

subgraph group_engine["PDF editing engine"]
  node_core_match["Target matching<br/>[pdf_edit_core.py]"]
  node_core_apply["Replace and redraw<br/>[pdf_edit_core.py]"]
  node_core_finalize["Finalize PDF<br/>[pdf_edit_core.py]"]
end

subgraph group_fonts["Font support"]
  node_font_resolve["Font resolution<br/>[pdf_edit_core.py]"]
  node_font_index[("Font index and cache<br/>[pdf_edit_core.py]")]
end

node_user(("User"))
node_pdf_input["Source PDF"]
node_pdf_output["Edited PDF"]
node_font_files[("System and user fonts")]

node_user -->|"edits PDF"| node_gui
node_pdf_input -->|"opens"| node_gui
node_gui -->|"selects and drafts"| node_gui_preview
node_gui_preview -->|"matches targets"| node_core_match
node_gui_preview -->|"builds preview"| node_core_apply
node_gui -->|"adds rules"| node_gui_rules
node_gui_rules -->|"exports edits"| node_core_apply
node_gui -->|"imports or exports"| node_config
node_user -->|"runs command"| node_cli
node_config -->|"configures"| node_cli
node_cli -->|"opens"| node_pdf_input
node_cli -->|"collects targets"| node_core_match
node_cli -->|"applies targets"| node_core_apply
node_core_apply -->|"matches if needed"| node_core_match
node_core_apply -->|"resolves settings"| node_font_resolve
node_font_resolve -->|"looks up fonts"| node_font_index
node_font_index -->|"scans font files"| node_font_files
node_core_apply -->|"finalizes document"| node_core_finalize
node_core_finalize -->|"writes"| node_pdf_output

click node_gui "https://github.com/kwong012/pdftexteditor/blob/compare-preview/pdf_editor_gui.py"
click node_gui_preview "https://github.com/kwong012/pdftexteditor/blob/compare-preview/pdf_editor_gui.py"
click node_gui_rules "https://github.com/kwong012/pdftexteditor/blob/compare-preview/pdf_editor_gui.py"
click node_cli "https://github.com/kwong012/pdftexteditor/blob/compare-preview/edit_pdf.py"
click node_config "https://github.com/kwong012/pdftexteditor/blob/compare-preview/config.example.json"
click node_core_match "https://github.com/kwong012/pdftexteditor/blob/compare-preview/pdf_edit_core.py"
click node_core_apply "https://github.com/kwong012/pdftexteditor/blob/compare-preview/pdf_edit_core.py"
click node_core_finalize "https://github.com/kwong012/pdftexteditor/blob/compare-preview/pdf_edit_core.py"
click node_font_resolve "https://github.com/kwong012/pdftexteditor/blob/compare-preview/pdf_edit_core.py"
click node_font_index "https://github.com/kwong012/pdftexteditor/blob/compare-preview/pdf_edit_core.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_gui,node_gui_preview,node_gui_rules,node_cli,node_config,node_user toneBlue
class node_core_match,node_core_apply,node_core_finalize,node_font_files toneAmber
class node_font_resolve,node_font_index toneMint
class node_pdf_input,node_pdf_output toneIndigo
```

## Components

### User interfaces

- [Desktop editor](https://github.com/kwong012/pdftexteditor/blob/compare-preview/pdf_editor_gui.py): `pdf_editor_gui.py`
- [Preview and selection](https://github.com/kwong012/pdftexteditor/blob/compare-preview/pdf_editor_gui.py): `pdf_editor_gui.py`
- [Change list](https://github.com/kwong012/pdftexteditor/blob/compare-preview/pdf_editor_gui.py): `pdf_editor_gui.py`
- [CLI entry point](https://github.com/kwong012/pdftexteditor/blob/compare-preview/edit_pdf.py): `edit_pdf.py`
- [Shared JSON config](https://github.com/kwong012/pdftexteditor/blob/compare-preview/config.example.json): `config.example.json`

### PDF editing engine

- [Target matching](https://github.com/kwong012/pdftexteditor/blob/compare-preview/pdf_edit_core.py): `pdf_edit_core.py`
- [Replace and redraw](https://github.com/kwong012/pdftexteditor/blob/compare-preview/pdf_edit_core.py): `pdf_edit_core.py`
- [Finalize PDF](https://github.com/kwong012/pdftexteditor/blob/compare-preview/pdf_edit_core.py): `pdf_edit_core.py`

### Font support

- [Font resolution](https://github.com/kwong012/pdftexteditor/blob/compare-preview/pdf_edit_core.py): `pdf_edit_core.py`
- [Font index and cache](https://github.com/kwong012/pdftexteditor/blob/compare-preview/pdf_edit_core.py): `pdf_edit_core.py`

### Other components

- **User**
- **Source PDF**
- **Edited PDF**
- **System and user fonts**

## Connections

- User → Desktop editor: edits PDF
- Source PDF → Desktop editor: opens
- Desktop editor → Preview and selection: selects and drafts
- Preview and selection → Target matching: matches targets
- Preview and selection → Replace and redraw: builds preview
- Desktop editor → Change list: adds rules
- Change list → Replace and redraw: exports edits
- Desktop editor → Shared JSON config: imports or exports
- User → CLI entry point: runs command
- Shared JSON config → CLI entry point: configures
- CLI entry point → Source PDF: opens
- CLI entry point → Target matching: collects targets
- CLI entry point → Replace and redraw: applies targets
- Replace and redraw → Target matching: matches if needed
- Replace and redraw → Font resolution: resolves settings
- Font resolution → Font index and cache: looks up fonts
- Font index and cache → System and user fonts: scans font files
- Replace and redraw → Finalize PDF: finalizes document
- Finalize PDF → Edited PDF: writes
