# tecnickcom/tc-lib-pdf architecture

> Architecture diagram of the GitHub repository tecnickcom/tc-lib-pdf, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-22). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/tecnickcom/tc-lib-pdf
- Repository: https://github.com/tecnickcom/tc-lib-pdf

## Overview

#### Purpose and Runtime

`tc-lib-pdf` is a Composer-distributed, pure-PHP 8.2+ PDF authoring library under `Com\Tecnick\Pdf`. It assembles PDF documents through a typed facade over companion packages for pages, fonts, graphics, images, filtering, encryption, and signing. Optional PHP extensions include GD and zlib.

Primary consumer entry point: instantiate `Tcpdf`, add pages/content, then serialize or render PDF bytes.
- `src/Tcpdf.php`
- `src/Base.php`
- `src/Output.php`

#### Core Document Facade and State

`Tcpdf` is the public orchestration API. `Base` initializes and retains document-level state and specialized collaborators; `Tcpdf` exposes authoring workflows such as page creation, content, HTML, import, and final output. This is a stateful, in-process library rather than a server application.
- `src/Tcpdf.php`
- `src/Base.php`
- `src/MetaInfo.php`

#### Content Authoring Pipeline

Callers compose pages using low-level text/cell operations or markup renderers. HTML is parsed and laid out with CSS cascade/specificity handling; SVG is separately translated into PDF drawing content. These stages feed page/content objects managed by companion services exposed from the base facade.
- `src/Text.php`
- `src/Cell.php`
- `src/HTML.php`
- `src/CSS.php`
- `src/SVG.php`

#### PDF Serialization and Delivery

The assembled object graph is finalized into raw PDF bytes, including metadata, document settings, page resources, and optional compression. Output supports returning bytes for storage/attachment or rendering to browser-oriented targets.
- `src/Output.php`
- `src/MetaInfo.php`
- `src/PdfConformance.php`

#### Compliance, Security, and Interactivity

Conformance policy constrains output for PDF/A, PDF/X, and PDF/UA. Security-capable document features include encryption through companion packages, embedded JavaScript, annotations/forms, and signed incremental revisions. Signature APIs isolate local and external/HSM signing flows behind a facade and support appearance configuration and encoding boundaries.
- `src/PdfConformance.php`
- `src/JavaScript.php`
- `src/Signature/Facade.php`
- `src/Signature/External.php`

External dependencies may include signing certificates/keys, remote signing services, RFC 3161 timestamp authorities, and OCSP/CRL revocation endpoints.

#### Existing-PDF Import Boundary

Import is a dedicated subsystem: source PDFs are loaded from paths or bytes, pages are resolved, source objects/resources are mapped and cloned, then represented as reusable page templates/Form XObjects in the destination document. It explicitly surfaces source, corruption, range, and unsupported-feature failures.
- `src/Import/Importer.php`
- `src/Import/SourceDocument.php`
- `src/Import/ResourceCloner.php`
- `src/Import/PageTemplate.php`

#### Asset, Resource, and Cache Boundaries

Fonts, images, ICC data, and remote/local assets are external-resource boundaries. Resource access is governed by caller-supplied policy; generated font assets are expected from a companion font package. Cache adapters allow external caching of costly font subsets and images without making caching mandatory.
- `src/Cache/CacheInterface.php`
- `src/Cache/FontSubsetCacheAdapter.php`
- `src/Cache/ImageCacheAdapter.php`
- `src/include/sRGB.icc.z`

#### Operational Entry Points

Runnable integration examples demonstrate intended API usage, while Composer supplies autoloading and dependency wiring. Local example serving is PHP’s development server via Make targets; CI runs GitHub Actions.
- `composer.json`
- `examples/E006_minimal.php`
- `examples/E000_overview.php`
- `.github/workflows/check.yml`

Main entry points: [`src/Tcpdf.php`](https://github.com/tecnickcom/tc-lib-pdf/blob/main/src/Tcpdf.php) (Tcpdf facade), [`src/Base.php`](https://github.com/tecnickcom/tc-lib-pdf/blob/main/src/Base.php) (Base document state), [`src/Output.php`](https://github.com/tecnickcom/tc-lib-pdf/blob/main/src/Output.php) (PDF output), [`src/Signature/Facade.php`](https://github.com/tecnickcom/tc-lib-pdf/blob/main/src/Signature/Facade.php) (Signature facade)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_authoring["Document authoring"]
  node_tcpdf["Tcpdf facade<br/>public API<br/>[Tcpdf.php]"]
  node_base["Base document state<br/>facade foundation<br/>[Base.php]"]
  node_text["Text operations<br/>authoring API<br/>[Text.php]"]
  node_cell["Cell layout<br/>authoring API<br/>[Cell.php]"]
  node_html["HTML layout<br/>markup renderer<br/>[HTML.php]"]
  node_css["CSS cascade<br/>style engine<br/>[CSS.php]"]
  node_svg["SVG renderer<br/>vector translator<br/>[SVG.php]"]
end

subgraph group_import["Existing PDF import"]
  node_importer["PDF importer<br/>import facade<br/>[Importer.php]"]
  node_source["Source document<br/>PDF parser boundary<br/>[SourceDocument.php]"]
  node_cloner["Resource cloner<br/>object mapper<br/>[ResourceCloner.php]"]
  node_template["Page template<br/>Form XObject<br/>[PageTemplate.php]"]
end

subgraph group_output["Output, policy &amp; signing"]
  node_metadata["Metadata<br/>[MetaInfo.php]"]
  node_conformance["PDF conformance<br/>policy engine<br/>[PdfConformance.php]"]
  node_javascript["Embedded JavaScript<br/>interactive feature<br/>[JavaScript.php]"]
  node_signature["Signature facade<br/>signing API<br/>[Facade.php]"]
  node_external_signing["External signing<br/>HSM/remote signer<br/>[External.php]"]
  node_output_api["PDF output<br/>serializer &amp; delivery<br/>[Output.php]"]
end

subgraph group_resources["External resources &amp; cache"]
  node_cache[("Cache adapters<br/>optional cache boundary<br/>[CacheInterface.php]")]
  node_font_cache["Font subset cache<br/>cache adapter"]
  node_image_cache["Image cache<br/>cache adapter"]
  node_assets["Assets &amp; font resources<br/>external resource boundary<br/>[sRGB.icc.z]"]
end

node_consumer(("Library consumer<br/>PHP application"))
node_pdf_bytes["PDF bytes<br/>serialized document"]

node_consumer -->|"instantiates"| node_tcpdf
node_tcpdf -->|"extends orchestration"| node_base
node_tcpdf -->|"authors content"| node_text
node_tcpdf -->|"lays out cells"| node_cell
node_tcpdf -->|"renders markup"| node_html
node_html -->|"resolves styles"| node_css
node_tcpdf -->|"renders vectors"| node_svg
node_tcpdf -->|"imports pages"| node_importer
node_importer -->|"loads"| node_source
node_source -->|"source objects"| node_cloner
node_cloner -->|"creates"| node_template
node_template -->|"added as page content"| node_base
node_base -->|"retains"| node_metadata
node_base -->|"applies policy"| node_conformance
node_base -->|"embeds"| node_javascript
node_tcpdf -->|"signs revisions"| node_signature
node_signature -.->|"delegates when external"| node_external_signing
node_tcpdf -->|"serializes"| node_output_api
node_metadata -->|"included in"| node_output_api
node_conformance -->|"constrains"| node_output_api
node_signature -->|"incremental revision"| node_output_api
node_output_api -->|"returns or renders"| node_pdf_bytes
node_base -.->|"uses resources"| node_assets
node_base -.->|"optional caching"| node_cache
node_cache -->|"font subsets"| node_font_cache
node_cache -->|"images"| node_image_cache

click node_tcpdf "https://github.com/tecnickcom/tc-lib-pdf/blob/main/src/Tcpdf.php"
click node_base "https://github.com/tecnickcom/tc-lib-pdf/blob/main/src/Base.php"
click node_text "https://github.com/tecnickcom/tc-lib-pdf/blob/main/src/Text.php"
click node_cell "https://github.com/tecnickcom/tc-lib-pdf/blob/main/src/Cell.php"
click node_html "https://github.com/tecnickcom/tc-lib-pdf/blob/main/src/HTML.php"
click node_css "https://github.com/tecnickcom/tc-lib-pdf/blob/main/src/CSS.php"
click node_svg "https://github.com/tecnickcom/tc-lib-pdf/blob/main/src/SVG.php"
click node_importer "https://github.com/tecnickcom/tc-lib-pdf/blob/main/src/Import/Importer.php"
click node_source "https://github.com/tecnickcom/tc-lib-pdf/blob/main/src/Import/SourceDocument.php"
click node_cloner "https://github.com/tecnickcom/tc-lib-pdf/blob/main/src/Import/ResourceCloner.php"
click node_template "https://github.com/tecnickcom/tc-lib-pdf/blob/main/src/Import/PageTemplate.php"
click node_metadata "https://github.com/tecnickcom/tc-lib-pdf/blob/main/src/MetaInfo.php"
click node_conformance "https://github.com/tecnickcom/tc-lib-pdf/blob/main/src/PdfConformance.php"
click node_javascript "https://github.com/tecnickcom/tc-lib-pdf/blob/main/src/JavaScript.php"
click node_signature "https://github.com/tecnickcom/tc-lib-pdf/blob/main/src/Signature/Facade.php"
click node_external_signing "https://github.com/tecnickcom/tc-lib-pdf/blob/main/src/Signature/External.php"
click node_output_api "https://github.com/tecnickcom/tc-lib-pdf/blob/main/src/Output.php"
click node_cache "https://github.com/tecnickcom/tc-lib-pdf/blob/main/src/Cache/CacheInterface.php"
click node_font_cache "https://github.com/tecnickcom/tc-lib-pdf/blob/main/src/Cache/FontSubsetCacheAdapter.php"
click node_image_cache "https://github.com/tecnickcom/tc-lib-pdf/blob/main/src/Cache/ImageCacheAdapter.php"
click node_assets "https://github.com/tecnickcom/tc-lib-pdf/blob/main/src/include/sRGB.icc.z"

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_tcpdf,node_base,node_text,node_cell,node_html,node_css,node_svg toneBlue
class node_importer,node_source,node_cloner,node_template toneAmber
class node_metadata,node_conformance,node_javascript,node_signature,node_external_signing,node_output_api toneMint
class node_cache,node_font_cache,node_image_cache,node_assets toneRose
class node_consumer,node_pdf_bytes toneNeutral
```

## Components

### Document authoring

Stateful APIs used to compose PDF content.

- [Tcpdf facade](https://github.com/tecnickcom/tc-lib-pdf/blob/main/src/Tcpdf.php): public API · Primary stateful document authoring entry point. · `src/Tcpdf.php`
- [Base document state](https://github.com/tecnickcom/tc-lib-pdf/blob/main/src/Base.php): facade foundation · Initializes document state and companion collaborators. · `src/Base.php`
- [Text operations](https://github.com/tecnickcom/tc-lib-pdf/blob/main/src/Text.php): authoring API · `src/Text.php`
- [Cell layout](https://github.com/tecnickcom/tc-lib-pdf/blob/main/src/Cell.php): authoring API · `src/Cell.php`
- [HTML layout](https://github.com/tecnickcom/tc-lib-pdf/blob/main/src/HTML.php): markup renderer · Parses markup into PDF content. · `src/HTML.php`
- [CSS cascade](https://github.com/tecnickcom/tc-lib-pdf/blob/main/src/CSS.php): style engine · Resolves CSS cascade and specificity for HTML. · `src/CSS.php`
- [SVG renderer](https://github.com/tecnickcom/tc-lib-pdf/blob/main/src/SVG.php): vector translator · Translates SVG into PDF drawing content. · `src/SVG.php`

### Existing PDF import

Converts source pages into reusable destination templates.

- [PDF importer](https://github.com/tecnickcom/tc-lib-pdf/blob/main/src/Import/Importer.php): import facade · Loads source PDFs and imports selected pages. · `src/Import/Importer.php`
- [Source document](https://github.com/tecnickcom/tc-lib-pdf/blob/main/src/Import/SourceDocument.php): PDF parser boundary · Represents source bytes or file and import failures. · `src/Import/SourceDocument.php`
- [Resource cloner](https://github.com/tecnickcom/tc-lib-pdf/blob/main/src/Import/ResourceCloner.php): object mapper · Maps and clones source objects and resources. · `src/Import/ResourceCloner.php`
- [Page template](https://github.com/tecnickcom/tc-lib-pdf/blob/main/src/Import/PageTemplate.php): Form XObject · Reusable imported page representation. · `src/Import/PageTemplate.php`

### Output, policy & signing

Finalizes, constrains, protects, and delivers documents.

- [Metadata](https://github.com/tecnickcom/tc-lib-pdf/blob/main/src/MetaInfo.php): document metadata · `src/MetaInfo.php`
- [PDF conformance](https://github.com/tecnickcom/tc-lib-pdf/blob/main/src/PdfConformance.php): policy engine · Applies PDF/A, PDF/X, and PDF/UA constraints. · `src/PdfConformance.php`
- [Embedded JavaScript](https://github.com/tecnickcom/tc-lib-pdf/blob/main/src/JavaScript.php): interactive feature · `src/JavaScript.php`
- [Signature facade](https://github.com/tecnickcom/tc-lib-pdf/blob/main/src/Signature/Facade.php): signing API · Isolates local and external signing flows. · `src/Signature/Facade.php`
- [External signing](https://github.com/tecnickcom/tc-lib-pdf/blob/main/src/Signature/External.php): HSM/remote signer · Connects to remote signing services and validation endpoints. · `src/Signature/External.php`
- [PDF output](https://github.com/tecnickcom/tc-lib-pdf/blob/main/src/Output.php): serializer & delivery · Finalizes document state into raw bytes or browser-oriented output. · `src/Output.php`

### External resources & cache

Caller-controlled assets and optional cache integrations.

- [Cache adapters](https://github.com/tecnickcom/tc-lib-pdf/blob/main/src/Cache/CacheInterface.php): optional cache boundary · Caches costly font subsets and images externally. · `src/Cache/CacheInterface.php`
- [Font subset cache](https://github.com/tecnickcom/tc-lib-pdf/blob/main/src/Cache/FontSubsetCacheAdapter.php): cache adapter · `src/Cache/FontSubsetCacheAdapter.php`
- [Image cache](https://github.com/tecnickcom/tc-lib-pdf/blob/main/src/Cache/ImageCacheAdapter.php): cache adapter · `src/Cache/ImageCacheAdapter.php`
- [Assets & font resources](https://github.com/tecnickcom/tc-lib-pdf/blob/main/src/include/sRGB.icc.z): external resource boundary · Caller-policy-governed fonts, images, ICC data, and local or remote assets. · `src/include/sRGB.icc.z`

### Other components

- **Library consumer**: PHP application
- **PDF bytes**: serialized document · Returned for storage, attachment, or rendering.

## Connections

- Library consumer → Tcpdf facade: instantiates
- Tcpdf facade → Base document state: extends orchestration
- Tcpdf facade → Text operations: authors content
- Tcpdf facade → Cell layout: lays out cells
- Tcpdf facade → HTML layout: renders markup
- HTML layout → CSS cascade: resolves styles
- Tcpdf facade → SVG renderer: renders vectors
- Tcpdf facade → PDF importer: imports pages
- PDF importer → Source document: loads
- Source document → Resource cloner: source objects
- Resource cloner → Page template: creates
- Page template → Base document state: added as page content
- Base document state → Metadata: retains
- Base document state → PDF conformance: applies policy
- Base document state → Embedded JavaScript: embeds
- Tcpdf facade → Signature facade: signs revisions
- Signature facade → External signing: delegates when external
- Tcpdf facade → PDF output: serializes
- Metadata → PDF output: included in
- PDF conformance → PDF output: constrains
- Signature facade → PDF output: incremental revision
- PDF output → PDF bytes: returns or renders
- Base document state → Assets & font resources: uses resources
- Base document state → Cache adapters: optional caching
- Cache adapters → Font subset cache: font subsets
- Cache adapters → Image cache: images
