Skip to main content

Dorsal PDF Extractor

Fast, deterministic PDF extraction using pdfium. Get native text and bounding boxes without the overhead of heavy AI layout models. Tesseract OCR fallback for scanned pages.

Features

  • Native Extraction: Extracts text and its bounding boxes directly from the PDF document.
  • Tesseract OCR Fallback: Optional optical character recognition (OCR) for scanned or empty pages.
  • Stable Block IDs: Extracting the same file again gives the same block ids, so annotations that refer to a block keep working.
  • Schema Compliant: Outputs records that validate against the OATS document-extraction schema.
  • Interactive HTML Export: Outputs can be exported to interactive HTML wireframes via the Dorsal CLI.

Quick Start

Install the model from PyPI, then run it against a local PDF file:

pip install dorsal-pdf-extractor
dorsal run dorsalhub/pdf-extractor ./document.pdf

This release needs Dorsal 0.13 (dorsalhub>=0.13.0,<0.14). Install it from PyPI first, as shown. Until DorsalHub's model registry lists this release, dorsal model install dorsalhub/pdf-extractor installs 0.6.0, and so does dorsal run dorsalhub/pdf-extractor if the model isn't installed yet. That replaces Dorsal 0.13 with Dorsal 0.12.1, and dorsal scan can then fail on the dorsal.toml entry it leaves.

Configuration Options

In the CLI, you can pass options to the model using the --opt (or -o) flag.

Example: Run the extractor with OCR fallback enabled for a French language document:

dorsal run dorsalhub/pdf-extractor ./document.pdf --opt use_ocr=true --opt ocr_language=fra

Options:

  • strict (default: false): Fail on a page with a zero or negative size, instead of clamping its boxes.
  • use_ocr (default: false): Run Tesseract OCR on pages where no native text is found.
  • ocr_language (default: "eng"): The Tesseract language code for OCR.
  • password (no default): The password for an encrypted PDF. It isn't set in model_config.toml, so pass it with --opt password=... when you need it.

OCR needs the ocr extra (pip install 'dorsal-pdf-extractor[ocr]', which installs pytesseract) and the Tesseract binary on your PATH.

Output Formats & Exporting

By default, the CLI outputs a validated JSON record to the current working directory.

You can export to other formats right from the CLI. For example, exporting to HTML:

dorsal run dorsalhub/pdf-extractor ./document.pdf --export=html

Output

This model produces a file annotation conforming to the OATS (Open Annotation Task Schemas) Document Extraction schema:

  • Schema ID: document-extraction (v0.8.0, pinned in model_config.toml). On Dorsal 0.13, use this bare name wherever you give a schema id yourself, for example dorsal adapter list document-extraction. The older open/document-extraction still works, but Dorsal 0.13 deprecates it: dorsal adapter commands print a warning, and run_model raises a DeprecationWarning.
  • Key Fields:
    • extraction_type: The type of extraction: boxes, text (OCR only) or mixed.
    • unit: per_mille. Box coordinates run from 0 to 1000 across the page, from the top-left corner.
    • page_width / page_height: The size of the pages in points, as Dorsal reports it (whole numbers for ordinary pages). A single number when every page has the same size, otherwise a list of sizes with their pages. A page whose size is reported as 0 is left out of the list.
    • blocks: One block per run of text that pdfium reports as a single rectangle (roughly one line), with id, block_type, text, page_number and, for native text, box. OCR gives one text block per page, with no box.
    • attributes: chunk_type, start_page and end_page. Dorsal uses these when it splits a large record into chunks.

Block IDs

Each block's id is p<page>-<hash>-<n>, for example p1-75690e15d48c-1:

  • <page> is the block's page_number;
  • <hash> is the first 12 hexadecimal characters of the SHA-256 digest of the block's text, encoded as UTF-8;
  • <n> counts, from 1, the blocks in the record with the same page and hash, in record order. It tells apart blocks with the same text on the same page.

The ids are unique within a record, including across the chunks Dorsal splits a large record into, and can be recomputed from the record alone. The same file, extracted with the same versions of this model, Dorsal, pypdfium2 and (for OCR) Tesseract, and the same options, always gives the same ids.

A block's id changes when its page or text changes, or when a block with the same text is added or removed before it on the same page. A change to a block's box alone, or to other blocks' text, leaves it unchanged.

The schema ID in model_config.toml

model_config.toml still says open/document-extraction, because DorsalHub's model registry doesn't accept a bare name yet. You won't see a deprecation warning from this: dorsal model install writes the bare name to dorsal.toml, and dorsal run prints no warning. A dorsal.toml written by an earlier Dorsal can still hold the old id, and dorsal scan then logs a warning. To stop it, change that schema_id to document-extraction.

Dorsal's results still report the schema as open/document-extraction in their schema_id field.

Development

Running Tests

This repository uses pytest for integration testing, and ruff and mypy for linting.

uv sync --extra ocr
uv run pytest
uv run ruff check .
uv run mypy

The OCR test is skipped unless the Tesseract binary is installed.

License

This project is licensed under the Apache 2.0 License.

Metadata

Release files for dorsal-pdf-extractor 0.7.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 dorsal-pdf-extractor 0.7.0
File Size Uploaded Provenance Actions
dorsal_pdf_extractor-0.7.0.tar.gz 119.8 kB Without provenance Details for dorsal_pdf_extractor-0.7.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for dorsal-pdf-extractor 0.7.0
File Interpreter ABI Platform Actions
dorsal_pdf_extractor-0.7.0-py3-none-any.whl Python 3 none any Details for dorsal_pdf_extractor-0.7.0-py3-none-any.whl

Total release size: 131.4 kB

Release files / dorsal_pdf_extractor-0.7.0.tar.gz

Download URL dorsal_pdf_extractor-0.7.0.tar.gz
Size 119.8 kB
Tags Source
SHA-256 checksum
How to use checksums
e6e61316269b2496d7cf250f29c18086c5d14ddae2778453586397c3d340b986
BLAKE2b-256 checksum
How to use checksums
1f4f11c4b42b97a7d0d88352d67abc8fa0ca834361490bb0df67b7c8dc34e518
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.1 {"installer":{"name":"uv","version":"0.13.1","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / dorsal_pdf_extractor-0.7.0-py3-none-any.whl

Download URL dorsal_pdf_extractor-0.7.0-py3-none-any.whl
Size 11.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a4a26cb93e3241c2e7b90a44b178233fc7cc4a6fa27e26bca4f76bb81954c531
BLAKE2b-256 checksum
How to use checksums
a6f6252706f2857e3fee35131213fd715e4dd2e44597f3270ddb1001d40181af
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.1 {"installer":{"name":"uv","version":"0.13.1","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for dorsal-pdf-extractor 0.7.0

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.7.0 This release

2 release files No provenance

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