Skip to main content

pdf-diagram-extract

PyPI version Python 3.10+ License: MIT

Extract diagram and graph entities from PDFs as structured JSON — no LLM, pure code.

📖 Documentation

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 file
  • pages (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.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pdf-diagram-extract 0.2.0
File Size Uploaded
pdf_diagram_extract-0.2.0.tar.gz 36.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pdf-diagram-extract 0.2.0
File Interpreter ABI Platform
pdf_diagram_extract-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 65.5 kB

Release files / pdf_diagram_extract-0.2.0.tar.gz

Download URL pdf_diagram_extract-0.2.0.tar.gz
Size 36.1 kB
Tags Source
SHA-256 checksum
How to use checksums
eb6fb92241c4ac515bc9cd4f5b0e34bac0041fc9221fbb6c255d623c5be7a2c6
BLAKE2b-256 checksum
How to use checksums
b51eef16e7d10e04331d65cc01cd9120af097faa06143b3b66e2aafadc68ad8f
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

Release files / pdf_diagram_extract-0.2.0-py3-none-any.whl

Download URL pdf_diagram_extract-0.2.0-py3-none-any.whl
Size 29.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b31bcc72031766e2e5a60253263a354780ea00ec5e24625b8e75ac29ac8e31e4
BLAKE2b-256 checksum
How to use checksums
c1114f2deb7a4755b087aedcb81cee8ef972be20364cd59153d3f411a07be8cd
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

Release history Release notifications | RSS feed

1.0.0

2 release files

This release

0.2.0 This release

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page