pdf-diagram-extract
Extract diagram and graph entities from PDFs as structured JSON — no LLM, pure code.
Features
- Vector extraction — parses native PDF drawing primitives (rectangles, lines, curves) via PyMuPDF
- Raster fallback — renders scanned/image-based pages and uses OpenCV contour detection
- Shape classification — identifies rectangles, circles, diamonds, ellipses, polygons
- Edge detection — detects lines, arrows, and curves with directionality
- Relationship resolution — links edges to shapes via spatial proximity
- Chart detection — heuristically identifies bar, pie, line, and scatter charts
- JSON output — returns a fully structured, serializable result
Installation
pip install pdf-diagram-extract
Or install from source:
git clone https://github.com/GT0096/pdf-diagram-extract.git
cd pdf-diagram-extract
pip install -e .
Quick Start
import diagramextract
import json
result = diagramextract.extract("path/to/document.pdf")
# Get JSON output
data = result.to_dict()
print(json.dumps(data, indent=2))
# Access specific pages
for page in result.pages:
print(f"Page {page.page_number}: {len(page.diagrams)} diagram(s)")
for diagram in page.diagrams:
print(f" Type: {diagram.diagram_type}")
print(f" Shapes: {len(diagram.shapes)}")
print(f" Edges: {len(diagram.edges)}")
print(f" Charts: {len(diagram.charts)}")
API Reference
diagramextract.extract(pdf_path, *, pages=None, vector_threshold=5, dpi=200)
Extract entities from all diagrams/graphs in a PDF.
Parameters:
pdf_path(str): Path to the PDF filepages(list[int] | None): Specific page numbers to process (0-indexed).None= all pages.vector_threshold(int): Minimum vector paths on a page to prefer vector extraction over raster fallback. Default:5.dpi(int): Resolution for raster rendering when falling back to image-based extraction. Default:200.
Returns: ExtractionResult with .to_dict() for JSON serialization.
Output Structure
{
"source_file": "document.pdf",
"total_pages": 3,
"pages": [
{
"page_number": 0,
"width": 612.0,
"height": 792.0,
"diagrams": [
{
"diagram_type": "flowchart",
"shapes": [...],
"edges": [...],
"charts": [...]
}
]
}
]
}
Dependencies
| Package | Purpose |
|---|---|
| PyMuPDF | PDF parsing, vector paths, page rendering |
| opencv-python-headless | Contour detection, shape classification |
| numpy | Numerical operations |
License
MIT
Release files for pdf-diagram-extract 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pdf_diagram_extract-0.1.0.tar.gz | 34.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pdf_diagram_extract-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 61.9 kB
Release files / pdf_diagram_extract-0.1.0.tar.gz
| Download URL | pdf_diagram_extract-0.1.0.tar.gz |
|---|---|
| Size | 34.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
464a9341b4a15cc75bbdf58386ee34a9052c14fb679b81bc9cab6248e26b8af4
|
|
BLAKE2b-256 checksum How to use checksums |
18d3843f8fbdbd398eb81da9fb5d9703939327bded3dc30a18ca81b3e6c11a64
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 25, 2026.
Transparency logRelease files / pdf_diagram_extract-0.1.0-py3-none-any.whl
| Download URL | pdf_diagram_extract-0.1.0-py3-none-any.whl |
|---|---|
| Size | 27.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
aa505b97edb497511039179ae9fbd953bbfc583765e8f37835470eec46cb8c61
|
|
BLAKE2b-256 checksum How to use checksums |
51d08b1b6b2f871e29b86a2874e78b7c14e0a91d257a160328a7163a355a219b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 25, 2026.
Transparency log