platen-document
A local-first Python SDK for PDF processing, OCR, document extraction, searchable PDFs, Markdown conversion, and PDF markup.
platen-document is a standalone document-processing SDK extracted from
PDFNest's OCR V2 engine.
It runs locally and does not require the PDFNest backend, PostgreSQL, Redis, Dramatiq, authentication, billing, HTTP services, or application storage.
Features
- Native PDF text extraction
- Automatic native/scanned-page routing
- Local Tesseract OCR
- Explicit OCR language selection
- Structured document extraction
- Word, line, block, and reading-order results
- Headings, lists, and bounded table extraction
- Markdown rendering
- Searchable PDF generation with invisible OCR text
- Highlight, Underline, and Strikeout markup
- Region-based PDF annotation
- OCR-aware region markup
- Extraction provenance and validation metadata
- Cooperative cancellation and progress callbacks
- Local environment and capability diagnostics
Installation
platen-document requires Python 3.12 or newer.
Install the SDK from PyPI:
pip install platen-document
System dependency
OCR features require a local Tesseract OCR installation.
On Ubuntu/Debian:
sudo apt update
sudo apt install tesseract-ocr
Additional Tesseract language packs can be installed separately when needed.
Verify the SDK and your local OCR environment:
platen-document doctor
Quick start
from platen_document import DocumentProcessor
processor = DocumentProcessor()
# Extract text
text_result = processor.extract_text("document.pdf")
print(text_result.text)
# Extract structured document data
document = processor.extract_document("document.pdf")
# Convert structured output to Markdown
markdown = processor.to_markdown(document)
print(markdown)
# Create a searchable PDF from a scanned document
processor.make_searchable_pdf(
"scanned.pdf",
"scanned-searchable.pdf",
)
Core workflows
Text extraction
from platen_document import DocumentProcessor
processor = DocumentProcessor()
result = processor.extract_text("document.pdf")
print(result.text)
The default routing behavior preserves validated native PDF text when appropriate and uses OCR when required.
Structured document extraction
from platen_document import DocumentProcessor
processor = DocumentProcessor()
document = processor.extract_document("document.pdf")
Structured extraction can include canonical document elements such as:
- words;
- lines;
- blocks;
- reading order;
- headings;
- lists;
- simple tables;
- provenance metadata; and
- validation results.
Markdown conversion
from platen_document import DocumentProcessor
processor = DocumentProcessor()
document = processor.extract_document("document.pdf")
markdown = processor.to_markdown(document)
print(markdown)
Searchable PDFs
Scanned PDFs can be converted into searchable PDFs by rendering invisible OCR text over the original pages.
from platen_document import DocumentProcessor
processor = DocumentProcessor()
processor.make_searchable_pdf(
"scanned.pdf",
"scanned-searchable.pdf",
)
Applications that need the canonical searchable-PDF profile can extract once and reuse the result during rendering:
from platen_document import DocumentProcessor, OCRProfile
processor = DocumentProcessor()
result = processor.extract_text(
"scanned.pdf",
profile=OCRProfile.SEARCHABLE_PDF_V2,
)
processor.make_searchable_pdf(
"scanned.pdf",
"scanned-searchable.pdf",
result=result,
job_id="optional-diagnostic-correlation",
)
Passing the existing result avoids performing a second OCR pass.
OCR routing and execution controls
extract_text() supports the engine's routing policy together with optional
cooperative execution controls such as:
cancellation_check;page_timeout_seconds;page_progress_callback; and- explicit OCR routing.
The default routing policy preserves validated native text when appropriate.
Applications that require OCR-only behavior can explicitly select:
result = processor.extract_text(
"document.pdf",
routing_policy="FORCE_OCR",
)
FORCE_OCR changes the selected route without changing the SDK's default
behavior for other consumers.
The SDK exposes these controls for application adapters but does not own application jobs, queues, or persistent storage.
Scanned table recognition
For upright scanned pages containing clear ruled tables, bounded table-aware structured extraction can be enabled explicitly.
from platen_document import (
DocumentProcessor,
EngineConfiguration,
)
processor = DocumentProcessor(
EngineConfiguration(
enable_scanned_table_recognition=True,
)
)
structured = processor.extract_document(
"scanned-table.pdf"
)
This path removes detected long ruling lines before the same OCR pass and reconstructs conservative aligned numeric rows.
It is designed for bounded, clearly structured scanned tables rather than arbitrary table recognition.
The feature is disabled by default:
enable_scanned_table_recognition=False
This keeps the default OCR and structured-extraction behavior stable for existing consumers.
Region-based markup
DocumentProcessor.apply_markup_regions() supports typed, one-based page
regions in the existing visible CropBox-relative PDF-point coordinate space.
Supported workflows include:
- manual region annotation;
- OCR-aware region annotation;
- Highlight;
- Underline;
- Strikeout;
- per-region colors;
- cooperative cancellation;
- progress callbacks; and
- reuse of an existing
DocumentResult.
Manual regions can be annotated without OCR.
OCR-aware regions can reuse an existing public DocumentResult to avoid a
second extraction pass. If no result is supplied, the SDK can perform one
public extract_text() pass.
See:
for the complete coordinate, password, result, overlap, and geometry contract.
Region geometry
Version 0.1.1 fixed native rotated-page region selection without changing
the public visible-region API or OCR/scanned geometry behavior.
Version 0.1.2 extended the same coordinate contract to manual region
annotation.
Visible input rectangles are mapped exactly once into canonical PDF coordinates at the PyMuPDF writer boundary.
Native PyMuPDF word boxes remain in unrotated PDF coordinates, while OCR boxes retain their existing visible-space behavior.
Configuration
Python dependencies are declared in pyproject.toml.
The SDK discovers the local Tesseract executable, tessdata directory, and installed language packs.
It does not install operating-system packages or download OCR models.
Custom paths can be configured explicitly:
from platen_document import (
DocumentProcessor,
EngineConfiguration,
)
processor = DocumentProcessor(
EngineConfiguration(
tesseract_binary="/usr/bin/tesseract",
tessdata_dir="/usr/share/tesseract-ocr/5/tessdata",
)
)
The engine also retains its tessdata fallback behavior, including fallback from
a stale TESSDATA_PREFIX when a known local system directory is available.
Raster DPI metadata
OCR raster images normally contain the configured DPI in their PNG metadata.
Applications that need to reproduce a historical OCR input contract can use the public compatibility policy:
from platen_document import (
DocumentProcessor,
EngineConfiguration,
RasterDpiMetadataPolicy,
)
processor = DocumentProcessor(
EngineConfiguration(
raster_dpi=144,
raster_dpi_metadata_policy=(
RasterDpiMetadataPolicy.OMIT_DPI
),
)
)
The default is:
RasterDpiMetadataPolicy.EMBED_DPI
OMIT_DPI changes only the encoded PNG DPI metadata.
It does not change:
- raster dimensions;
- rendered pixels;
- page geometry;
- OCR language selection; or
- routing policy.
This option is intended for consumer-specific compatibility requirements.
Diagnostics
Inspect the local SDK environment with:
platen-document doctor
The command reports safe local capability metadata such as OCR and runtime availability.
It does not know about PDFNest:
- users;
- guests;
- quotas;
- jobs;
- queues;
- storage providers;
- authentication;
- billing; or
- application secrets.
Capabilities can also be inspected programmatically:
from platen_document import DocumentProcessor
processor = DocumentProcessor()
capabilities = processor.capabilities()
print(capabilities)
Local-first architecture
platen-document is intentionally independent of the PDFNest application
runtime.
The SDK can process local documents without:
PDFNest backend
PostgreSQL
Redis
Dramatiq
Frontend services
HTTP APIs
Authentication
Billing
Cloud storage
Application job orchestration
Applications remain responsible for concerns such as:
- authentication;
- authorization;
- quotas;
- rate limits;
- durable job orchestration;
- storage;
- cleanup;
- API routes; and
- user interfaces.
This keeps the SDK usable as a standalone document-processing library.
PDFNest integration
PDFNest uses independent execution boundaries that allow document-processing consumers to select between its internal implementation and this SDK.
Current integration boundaries include:
- OCR Text V2 —
OCR_TEXT_ENGINE - Searchable PDF V2 —
SEARCHABLE_PDF_ENGINE - Document Extraction V2 —
DOCUMENT_EXTRACTION_ENGINE - PDF-to-Markdown V2 —
PDF_TO_MARKDOWN_ENGINE - OCR-aware Highlight / Underline / Strikeout —
OCR_MARKUP_ENGINE - General Editor OCR —
EDITOR_OCR_ENGINE
Each selector keeps its own application-level execution boundary.
The SDK itself does not contain PDFNest application routing, authentication, quota, billing, or storage logic.
Project status
platen-document is currently in the 0.1.x release series.
These releases prioritize compatibility and parity with the validated OCR V2 engine from which the SDK was extracted.
The default detector, rendering behavior, routing policy, and validation contracts are intentionally kept conservative.
New capabilities that can materially change extraction behavior are introduced as explicit opt-in features where appropriate.
Development
Clone the repository:
git clone https://github.com/gimesha-adikari/platen-document.git
cd platen-document
Create a virtual environment:
python3 -m venv .venv
source .venv/bin/activate
Install the project with development dependencies:
pip install -e ".[dev]"
Run the test suite:
pytest
Build distributions:
python -m build
The generated wheel and source distribution will be placed in:
dist/
Requirements
See the raster security contract for mandatory raster limits, typed rejection behavior, compatibility changes and remaining native isolation requirements in the proposed 0.1.9 patch.
- Python 3.12+
- Tesseract OCR
- PyMuPDF
- Pillow
- pdfplumber
License
Licensed under the Apache License 2.0.
Metadata
Release files for platen-document 0.1.9
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| platen_document-0.1.9.tar.gz | 106.4 kB | With provenance | Details for platen_document-0.1.9.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| platen_document-0.1.9-py3-none-any.whl | Python 3 | none | any | Details for platen_document-0.1.9-py3-none-any.whl |
Total release size: 197.0 kB
Release files / platen_document-0.1.9.tar.gz
| Download URL | platen_document-0.1.9.tar.gz |
|---|---|
| Size | 106.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
74634f3e23dda9ed1740e1a840e263db47ab255a6a431ade8fe7bdff5d2f90f1
|
|
BLAKE2b-256 checksum How to use checksums |
214470604542d4bedff7b2fa0ab7c8300c5ea1970f34ae15730d717882b69849
|
| 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 Oct 20, 2026.
Transparency logRelease files / platen_document-0.1.9-py3-none-any.whl
| Download URL | platen_document-0.1.9-py3-none-any.whl |
|---|---|
| Size | 90.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
70919a01664643b7b5e95d38d893b61b326b9e57bb0a0ddadf79d135c214e21b
|
|
BLAKE2b-256 checksum How to use checksums |
d50271185dcb1f95f4d005c049b0400deabc4e7fa65509591e9f5af2b0b2ddea
|
| 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 Oct 20, 2026.
Transparency logSecurity for platen-document 0.1.9
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.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for platen_document-0.1.9.tar.gz
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 Oct 20, 2026.
Transparency logA 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.