# belval/pdf2image architecture

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

- Interactive diagram: https://gitdiagram.com/belval/pdf2image
- Repository: https://github.com/belval/pdf2image

## Overview

#### Purpose and Public API
`pdf2image` is a Python 3.7+ library that converts PDF pages into Pillow (`PIL.Image`) images or persisted image paths. It wraps Poppler command-line utilities rather than implementing PDF rendering. Public imports and conversion entry points are exposed through:
- `pdf2image/__init__.py`
- `pdf2image/pdf2image.py`

Primary APIs are `convert_from_path`, `convert_from_bytes`, `pdfinfo_from_path`, and `pdfinfo_from_bytes`.

#### Input and Metadata Stage
Path-based conversion begins by querying Poppler `pdfinfo` for page count and document metadata, then validates page ranges and conversion options. Byte-based APIs adapt in-memory PDFs into the same path-oriented pipeline, typically through temporary files.
- `pdf2image/pdf2image.py`
- `pdf2image/parsers.py`

This boundary separates PDF/source handling from rendering and makes Poppler availability a runtime requirement.

#### Poppler Process Orchestration
The core module builds and launches subprocess commands for `pdfinfo`, `pdftoppm`, or optionally `pdftocairo`. It maps API options—DPI, output format, crop box, passwords, transparency, grayscale, sizing, JPEG settings, timeout, and explicit Poppler installation path—to CLI arguments.
- `pdf2image/pdf2image.py`
- `pdf2image/generators.py`

External executables are resolved from `PATH` or `poppler_path`; Windows-specific process behavior is handled at this boundary.

#### Parallel Page Rendering
For multi-page documents, the conversion layer partitions page ranges across a caller-controlled thread count and starts independent Poppler processes. Each process renders its assigned pages into a specified output directory or a managed temporary directory.
- `pdf2image/pdf2image.py`
- `pdf2image/generators.py`

The concurrency model is process orchestration from Python, while rendering remains in native Poppler utilities. Disk output is an important performance and memory boundary.

#### Output Materialization
Rendered files are either loaded with Pillow and returned as a list of image objects, or returned as file paths when `paths_only=True`. Format selection controls both the Poppler executable/flags and image-loading behavior. Temporary output is retained only as needed to construct in-memory images.
- `pdf2image/pdf2image.py`

This stage provides the main memory-management tradeoff: image objects are convenient but can exhaust memory for large PDFs; path-only/output-folder workflows keep results on disk.

#### Parsing and Failure Semantics
Poppler stdout/stderr is parsed into Python metadata and normalized into library-specific errors for missing executables, page-count failures, malformed PDFs, password failures, and conversion timeouts. Strict mode can surface PDF syntax errors detected during rendering.
- `pdf2image/parsers.py`
- `pdf2image/exceptions.py`
- `pdf2image/pdf2image.py`

#### Packaging and Runtime Dependencies
The distributable Python package is defined by setuptools configuration and includes typing metadata. Runtime integration depends materially on Pillow and a separately installed Poppler distribution providing `pdfinfo`, `pdftoppm`, and optionally `pdftocairo`.
- `setup.py`
- `setup.cfg`
- `pdf2image/py.typed`

Main entry points: [`pdf2image/pdf2image.py`](https://github.com/belval/pdf2image/blob/master/pdf2image/pdf2image.py) (Source validation), [`pdf2image/parsers.py`](https://github.com/belval/pdf2image/blob/master/pdf2image/parsers.py) (Poppler output parsers), [`pdf2image/__init__.py`](https://github.com/belval/pdf2image/blob/master/pdf2image/__init__.py) (Public imports), [`setup.py`](https://github.com/belval/pdf2image/blob/master/setup.py) (Package distribution)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["Python API"]
  node_package_exports["Public imports<br/>package facade<br/>[__init__.py]"]
  node_conversion_api["Conversion APIs<br/>Python module<br/>[pdf2image.py]"]
  node_metadata_api["Metadata APIs<br/>Python module<br/>[pdf2image.py]"]
end

subgraph group_pipeline["Conversion Pipeline"]
  node_byte_input["Byte input adapter<br/>input stage<br/>[pdf2image.py]"]
  node_source_validation["Source validation<br/>pipeline stage<br/>[pdf2image.py]"]
  node_command_generation["CLI command builder<br/>command layer<br/>[generators.py]"]
  node_process_orchestrator{{"Poppler orchestration<br/>process layer<br/>[pdf2image.py]"}}
  node_page_partitioning["Page partitioning<br/>parallelism layer<br/>[pdf2image.py]"]
  node_disk_render_output[("Rendered files<br/>disk boundary<br/>[pdf2image.py]")]
  node_output_materialization["Output materialization<br/>output stage<br/>[pdf2image.py]"]
  node_stdout_stderr_parsers["Poppler output parsers<br/>parser module<br/>[parsers.py]"]
  node_library_errors["Library errors<br/>exception module<br/>[exceptions.py]"]
end

subgraph group_runtime["Runtime Dependencies"]
  node_poppler_pdfinfo{{"pdfinfo<br/>external executable"}}
  node_poppler_renderers{{"pdftoppm / pdftocairo<br/>external executables"}}
  node_pillow["Pillow<br/>Python dependency"]
  node_package_distribution["Package distribution<br/>setuptools config<br/>[setup.py]"]
  node_package_metadata["Package metadata<br/>setuptools config<br/>[setup.cfg]"]
  node_typing_marker["Typing marker<br/>package metadata<br/>[py.typed]"]
end

node_package_exports -->|"exports"| node_conversion_api
node_package_exports -->|"exports"| node_metadata_api
node_conversion_api -->|"bytes input"| node_byte_input
node_byte_input -->|"temporary PDF path"| node_source_validation
node_conversion_api -->|"path input"| node_source_validation
node_metadata_api -->|"queries"| node_source_validation
node_source_validation -->|"validated options"| node_command_generation
node_source_validation -->|"page count / metadata"| node_poppler_pdfinfo
node_poppler_pdfinfo -->|"stdout / stderr"| node_stdout_stderr_parsers
node_stdout_stderr_parsers -->|"normalizes failures"| node_library_errors
node_command_generation -->|"render plan"| node_page_partitioning
node_page_partitioning -->|"worker page ranges"| node_process_orchestrator
node_process_orchestrator -->|"launches"| node_poppler_renderers
node_poppler_renderers -->|"writes page images"| node_disk_render_output
node_disk_render_output -->|"rendered files"| node_output_materialization
node_output_materialization -->|"loads image objects"| node_pillow
node_process_orchestrator -->|"captures diagnostics"| node_stdout_stderr_parsers
node_package_distribution -->|"uses"| node_package_metadata
node_package_distribution -->|"includes"| node_typing_marker

click node_package_exports "https://github.com/belval/pdf2image/blob/master/pdf2image/__init__.py"
click node_conversion_api "https://github.com/belval/pdf2image/blob/master/pdf2image/pdf2image.py"
click node_metadata_api "https://github.com/belval/pdf2image/blob/master/pdf2image/pdf2image.py"
click node_byte_input "https://github.com/belval/pdf2image/blob/master/pdf2image/pdf2image.py"
click node_source_validation "https://github.com/belval/pdf2image/blob/master/pdf2image/pdf2image.py"
click node_command_generation "https://github.com/belval/pdf2image/blob/master/pdf2image/generators.py"
click node_process_orchestrator "https://github.com/belval/pdf2image/blob/master/pdf2image/pdf2image.py"
click node_page_partitioning "https://github.com/belval/pdf2image/blob/master/pdf2image/pdf2image.py"
click node_disk_render_output "https://github.com/belval/pdf2image/blob/master/pdf2image/pdf2image.py"
click node_output_materialization "https://github.com/belval/pdf2image/blob/master/pdf2image/pdf2image.py"
click node_stdout_stderr_parsers "https://github.com/belval/pdf2image/blob/master/pdf2image/parsers.py"
click node_library_errors "https://github.com/belval/pdf2image/blob/master/pdf2image/exceptions.py"
click node_package_distribution "https://github.com/belval/pdf2image/blob/master/setup.py"
click node_package_metadata "https://github.com/belval/pdf2image/blob/master/setup.cfg"
click node_typing_marker "https://github.com/belval/pdf2image/blob/master/pdf2image/py.typed"

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_package_exports,node_conversion_api,node_metadata_api toneBlue
class node_byte_input,node_source_validation,node_command_generation,node_process_orchestrator,node_page_partitioning,node_disk_render_output,node_output_materialization,node_stdout_stderr_parsers,node_library_errors toneAmber
class node_poppler_pdfinfo,node_poppler_renderers,node_pillow,node_package_distribution,node_package_metadata,node_typing_marker toneMint
```

## Components

### Python API

- [Public imports](https://github.com/belval/pdf2image/blob/master/pdf2image/__init__.py): package facade · Exports the supported conversion and metadata APIs. · `pdf2image/__init__.py`
- [Conversion APIs](https://github.com/belval/pdf2image/blob/master/pdf2image/pdf2image.py): Python module · Path- and byte-based PDF conversion entry points. · `pdf2image/pdf2image.py`
- [Metadata APIs](https://github.com/belval/pdf2image/blob/master/pdf2image/pdf2image.py): Python module · pdfinfo-based document metadata entry points. · `pdf2image/pdf2image.py`

### Conversion Pipeline

- [Byte input adapter](https://github.com/belval/pdf2image/blob/master/pdf2image/pdf2image.py): input stage · Writes in-memory PDFs into the path-oriented workflow. · `pdf2image/pdf2image.py`
- [Source validation](https://github.com/belval/pdf2image/blob/master/pdf2image/pdf2image.py): pipeline stage · Obtains page count and validates ranges and options. · `pdf2image/pdf2image.py`
- [CLI command builder](https://github.com/belval/pdf2image/blob/master/pdf2image/generators.py): command layer · Maps Python options to Poppler command arguments. · `pdf2image/generators.py`
- [Poppler orchestration](https://github.com/belval/pdf2image/blob/master/pdf2image/pdf2image.py): process layer · Resolves executables and launches subprocesses. · `pdf2image/pdf2image.py`
- [Page partitioning](https://github.com/belval/pdf2image/blob/master/pdf2image/pdf2image.py): parallelism layer · Splits page ranges across caller-selected workers. · `pdf2image/pdf2image.py`
- [Rendered files](https://github.com/belval/pdf2image/blob/master/pdf2image/pdf2image.py): disk boundary · Uses caller output folders or managed temporary storage. · `pdf2image/pdf2image.py`
- [Output materialization](https://github.com/belval/pdf2image/blob/master/pdf2image/pdf2image.py): output stage · Returns Pillow images or persisted file paths. · `pdf2image/pdf2image.py`
- [Poppler output parsers](https://github.com/belval/pdf2image/blob/master/pdf2image/parsers.py): parser module · Parses metadata and rendering diagnostics. · `pdf2image/parsers.py`
- [Library errors](https://github.com/belval/pdf2image/blob/master/pdf2image/exceptions.py): exception module · Normalizes executable, PDF, password, and timeout failures. · `pdf2image/exceptions.py`

### Runtime Dependencies

- **pdfinfo**: external executable · Supplies page count and PDF metadata.
- **pdftoppm / pdftocairo**: external executables · Native PDF page renderers; Cairo is optional.
- **Pillow**: Python dependency · Loads rendered files into PIL.Image objects.
- [Package distribution](https://github.com/belval/pdf2image/blob/master/setup.py): setuptools config · Defines the distributable package and typing metadata. · `setup.py`
- [Package metadata](https://github.com/belval/pdf2image/blob/master/setup.cfg): setuptools config · `setup.cfg`
- [Typing marker](https://github.com/belval/pdf2image/blob/master/pdf2image/py.typed): package metadata · Marks bundled type information. · `pdf2image/py.typed`

## Connections

- Public imports → Conversion APIs: exports
- Public imports → Metadata APIs: exports
- Conversion APIs → Byte input adapter: bytes input
- Byte input adapter → Source validation: temporary PDF path
- Conversion APIs → Source validation: path input
- Metadata APIs → Source validation: queries
- Source validation → CLI command builder: validated options
- Source validation → pdfinfo: page count / metadata
- pdfinfo → Poppler output parsers: stdout / stderr
- Poppler output parsers → Library errors: normalizes failures
- CLI command builder → Page partitioning: render plan
- Page partitioning → Poppler orchestration: worker page ranges
- Poppler orchestration → pdftoppm / pdftocairo: launches
- pdftoppm / pdftocairo → Rendered files: writes page images
- Rendered files → Output materialization: rendered files
- Output materialization → Pillow: loads image objects
- Poppler orchestration → Poppler output parsers: captures diagnostics
- Package distribution → Package metadata: uses
- Package distribution → Typing marker: includes
