Skip to main content

High-level PDF transformations backed by Apache PDFBox

Project description

py-pdftools

py-pdftools is a Python library for high-level PDF transformations backed by Apache PDFBox and compiled to a native library with GraalVM Native Image.

The initial release adds invisible, searchable OCR text layers to existing PDFs without requiring Java at runtime. It accepts provider-independent OCR lines, maps normalized visible-page coordinates through crop boxes and page rotation, fits and embeds Unicode text, and returns a new PDF as bytes.

The project is pre-release. The implementation works end to end and all five supported platform wheels pass CI, but no package has been published to PyPI yet. See PROGRESS.md for the current release status.

Installation

Once the first release is published:

python -m pip install tindtechnologies-py-pdftools

The PyPI distribution is named tindtechnologies-py-pdftools; the Python import remains py_pdftools.

Runtime requirements

  • Python 3.10 or newer.
  • A platform wheel matching Linux x86-64/ARM64, macOS x86-64/ARM64, or Windows x86-64.
  • No Java, JVM, Gradle, Maven, or GraalVM installation.

Until wheels are published, build one from source using BUILDING.md.

Add an OCR text layer

from pathlib import Path

from py_pdftools import (
    NormalizedRect,
    OcrDocument,
    OcrLine,
    OcrPage,
    OcrTextLayerOptions,
    add_ocr_text_layer,
)

source = Path("scan.pdf").read_bytes()
ocr = OcrDocument(
    pages=(
        OcrPage(
            page_index=0,
            orientation=0,
            lines=(
                OcrLine(
                    text="Example OCR text",
                    bounds=NormalizedRect(
                        left=0.10,
                        top=0.20,
                        width=0.40,
                        height=0.03,
                    ),
                    confidence=98.4,
                ),
            ),
        ),
    ),
)

result = add_ocr_text_layer(
    source,
    ocr,
    options=OcrTextLayerOptions(minimum_confidence=80.0),
)
Path("searchable.pdf").write_bytes(result)

OCR bounds use normalized coordinates relative to the visible crop box after page rotation. The origin is at the visible top-left. orientation is the OCR text direction in that same visible coordinate system and must be one of 0, 90, 180, or 270.

By default the OCR document must contain every PDF page exactly once. Set allow_partial_document=True to modify only supplied pages. Lines below minimum_confidence are skipped; lines without confidence are retained. debug_visible_text=True renders the inserted text for placement diagnostics.

Inspect page geometry

from pathlib import Path

from py_pdftools import inspect_pdf

info = inspect_pdf(Path("scan.pdf").read_bytes())
for page in info.pages:
    print(
        page.page_index,
        page.width_points,
        page.height_points,
        page.rotation,
        page.crop_box,
    )

Visible width and height reflect the crop box after page rotation. Box coordinates themselves remain in PDF user space.

Behavior and limits

  • Existing page streams are preserved and the OCR layer is appended.
  • Normal OCR text uses PDF rendering mode 3 (neither fill nor stroke), while remaining searchable and extractable.
  • Noto Sans is subset and embedded. Unsupported characters raise FontError instead of being silently replaced.
  • Ordinary left-to-right text is supported. Advanced bidirectional and complex script shaping is not guaranteed in version 0.1.
  • The library consumes OCR results; it does not render pages or run an OCR engine.
  • Password input is not supported. PDFs requiring a password raise PdfPasswordRequiredError, and modification restrictions raise PdfPermissionError.

All public failures derive from PdfToolsError. More specific exceptions distinguish invalid PDFs, invalid OCR data, page mismatches, font coverage, permissions, native loading, and PDF processing failures.

License

Project code is licensed under the Apache License 2.0. The bundled Noto Sans font is licensed separately under the SIL Open Font License 1.1. See LICENSE, NOTICE, and the bundled third-party license texts for details.

Project documentation

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

tindtechnologies_py_pdftools-0.1.0-py3-none-win_amd64.whl (14.7 MB view details)

Uploaded Python 3Windows x86-64

tindtechnologies_py_pdftools-0.1.0-py3-none-manylinux_2_28_x86_64.whl (14.8 MB view details)

Uploaded Python 3manylinux: glibc 2.28+ x86-64

tindtechnologies_py_pdftools-0.1.0-py3-none-manylinux_2_28_aarch64.whl (14.4 MB view details)

Uploaded Python 3manylinux: glibc 2.28+ ARM64

tindtechnologies_py_pdftools-0.1.0-py3-none-macosx_11_0_arm64.whl (12.6 MB view details)

Uploaded Python 3macOS 11.0+ ARM64

tindtechnologies_py_pdftools-0.1.0-py3-none-macosx_10_15_x86_64.whl (12.7 MB view details)

Uploaded Python 3macOS 10.15+ x86-64

File details

Details for the file tindtechnologies_py_pdftools-0.1.0-py3-none-win_amd64.whl.

File metadata

File hashes

Hashes for tindtechnologies_py_pdftools-0.1.0-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 01237879b32fd9ec72cf708eb4a18d60992a8807dff285db1fe895f965ac970f
MD5 0315d805ab4b187d17a4a68b5f386655
BLAKE2b-256 562a0f41cc12fc5a7a47ebaebb4e8f2e92bc6ebe3386cd23b383de7a425cfd4f

See more details on using hashes here.

Provenance

The following attestation bundles were made for tindtechnologies_py_pdftools-0.1.0-py3-none-win_amd64.whl:

Publisher: publish.yml on tind/py-pdftools

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tindtechnologies_py_pdftools-0.1.0-py3-none-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for tindtechnologies_py_pdftools-0.1.0-py3-none-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 999a09905b2025b1b485bc3e6457e49f3bf37dab931b29b7fedac89e1499c9b6
MD5 3e3de6d3443b616e998cf15d62a422dc
BLAKE2b-256 6c99cd029ebdc158b100c9ee3a9c168f582d6aaeb97fc37b0d8540511ba575a3

See more details on using hashes here.

Provenance

The following attestation bundles were made for tindtechnologies_py_pdftools-0.1.0-py3-none-manylinux_2_28_x86_64.whl:

Publisher: publish.yml on tind/py-pdftools

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tindtechnologies_py_pdftools-0.1.0-py3-none-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for tindtechnologies_py_pdftools-0.1.0-py3-none-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 fff3c17259ed813fa3a2a08c07302ac8362221042cc827281ad4d0287e0e0c2b
MD5 98556900dba4393090d8ec0ec0fbea6b
BLAKE2b-256 acca62a838309fc7c7e23eb0a916111dad0e61ca3fce6c0bb169a4cb01fe5d4d

See more details on using hashes here.

Provenance

The following attestation bundles were made for tindtechnologies_py_pdftools-0.1.0-py3-none-manylinux_2_28_aarch64.whl:

Publisher: publish.yml on tind/py-pdftools

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tindtechnologies_py_pdftools-0.1.0-py3-none-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for tindtechnologies_py_pdftools-0.1.0-py3-none-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 3199b09d4dc78a2d13c24c8b5f10a364150bb9b628f90d0c4f99b4d8d136a058
MD5 a3a01c6474faf26cc21a8ca3d0e9ba72
BLAKE2b-256 b08b577bdefe861f30040b17701fcb0d8e3c857c42525e92c13ceb0f2ab87c93

See more details on using hashes here.

Provenance

The following attestation bundles were made for tindtechnologies_py_pdftools-0.1.0-py3-none-macosx_11_0_arm64.whl:

Publisher: publish.yml on tind/py-pdftools

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tindtechnologies_py_pdftools-0.1.0-py3-none-macosx_10_15_x86_64.whl.

File metadata

File hashes

Hashes for tindtechnologies_py_pdftools-0.1.0-py3-none-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 4002200084e0dc8d7a8bf2d307203286779fae5b29f37573a432f3e0ab0ad75c
MD5 165617fb22c39e58b861ffd2eb8805a0
BLAKE2b-256 f0de451ba162b06f3dd333ea3f345480a869b7fdaaa1ee8b2d8c470a1b188422

See more details on using hashes here.

Provenance

The following attestation bundles were made for tindtechnologies_py_pdftools-0.1.0-py3-none-macosx_10_15_x86_64.whl:

Publisher: publish.yml on tind/py-pdftools

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page