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.

Self-contained wheels are available from PyPI for all five supported platforms. The complete implementation passes native, Python, installation, and installed-wheel smoke tests. See PROGRESS.md for the release verification record.

Installation

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.

To build a wheel from source, use 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.1-py3-none-win_amd64.whl (14.7 MB view details)

Uploaded Python 3Windows x86-64

tindtechnologies_py_pdftools-0.1.1-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.1-py3-none-manylinux_2_28_aarch64.whl (14.4 MB view details)

Uploaded Python 3manylinux: glibc 2.28+ ARM64

tindtechnologies_py_pdftools-0.1.1-py3-none-macosx_11_0_arm64.whl (12.7 MB view details)

Uploaded Python 3macOS 11.0+ ARM64

tindtechnologies_py_pdftools-0.1.1-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.1-py3-none-win_amd64.whl.

File metadata

File hashes

Hashes for tindtechnologies_py_pdftools-0.1.1-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 18aa6d08b1fd7b7562bc34fcd0608c3855e4fa6d8a112bb4bb83ccd29c51dfe4
MD5 84938ec5beb1578c03935f46b2398a7f
BLAKE2b-256 feabb2cea49c42495be360894abad18c817735f744c5afb28c635b3a580d6097

See more details on using hashes here.

Provenance

The following attestation bundles were made for tindtechnologies_py_pdftools-0.1.1-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.1-py3-none-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for tindtechnologies_py_pdftools-0.1.1-py3-none-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 91a2d1d46f2eb913d994bc999ae0d3e76605428bd7fde7c71782401d52ed81c0
MD5 a79d955233c36e85ed579053eb88f094
BLAKE2b-256 0bce649212f167f09147c5c93854f5b106814b156256a135363fdbe7d31e7c4f

See more details on using hashes here.

Provenance

The following attestation bundles were made for tindtechnologies_py_pdftools-0.1.1-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.1-py3-none-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for tindtechnologies_py_pdftools-0.1.1-py3-none-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 653043a0c626487e085c468fe4319cf487105a4b3f81f592d985b7562cee312b
MD5 70059c0b63996e0b23dc28b1d9f2a90f
BLAKE2b-256 db5e7926f5b02d9ef223ff5088a8c67b41dc81f2bac29934e85ba85e708e3594

See more details on using hashes here.

Provenance

The following attestation bundles were made for tindtechnologies_py_pdftools-0.1.1-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.1-py3-none-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for tindtechnologies_py_pdftools-0.1.1-py3-none-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 2a3234ab1f1a78856ce47943158e55c517c2031d73289dbe544a5ca7ab7bddab
MD5 8fe29d56502c39036df988233ed3a34d
BLAKE2b-256 bf4996b4bf2083cac27dec162b3e44b3de35679a095a64a659f579ffcca6bedd

See more details on using hashes here.

Provenance

The following attestation bundles were made for tindtechnologies_py_pdftools-0.1.1-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.1-py3-none-macosx_10_15_x86_64.whl.

File metadata

File hashes

Hashes for tindtechnologies_py_pdftools-0.1.1-py3-none-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 5677657cd09d2beb38f62b70728e3f33ac96c457e97df26cac5c5a945f46837b
MD5 4af1361f04686d58dbce8b81b2b50862
BLAKE2b-256 ffcc629a1b4a1847711b9839687d6c8b63615173a334d57362ad408620c4b6b5

See more details on using hashes here.

Provenance

The following attestation bundles were made for tindtechnologies_py_pdftools-0.1.1-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