pdf-ocr
OCR integration for PDFluent — bring your own recognizer, we do the PDF.
This crate is part of PDFluent, a pure-Rust PDF SDK. Source: https://github.com/pdfluent/pdfluent-sdk.
AGPL-3.0 or a commercial licence, at your option — see the Licence section below.
What it does
Turns a scanned PDF into a searchable one. You provide the character recognition; this crate renders the pages, hands them to your recognizer, and writes the words back as an invisible text layer positioned over the image.
The recognizer is a trait:
Implement it against whatever you already use — Google Cloud Vision, AWS
Textract, Azure Document Intelligence, a self-hosted service, a local binary —
and pass it to make_searchable together with a page-render callback. You get
back an OcrReport per page.
Two local backends ship behind their own feature flags, and they are not equivalent:
paddle — PaddleOCR via ONNX. Detection with DBNet, recognition with SVTR,
optional angle classification. Handles English, Latin scripts, Chinese, Japanese,
Korean and Arabic. It uses ort with load-dynamic, so ONNX Runtime is loaded as
a shared library at run time rather than compiled in, and the model weights are
downloaded once (tens of megabytes for the current detection model) and cached in the OS
cache directory. After that first fetch it runs entirely offline, in-process, with
no cloud calls.
tesseract — Tesseract 4 or 5 through leptess. Requires the Tesseract and
Leptonica system libraries to be installed.
Neither is on by default, and the pdfluent facade wires neither, so a plain
pdfluent dependency pulls in no system libraries and downloads no models.
Opting in is a decision you make rather than a side effect of using the SDK.
Status
The seam and the text-layer work are stable in shape. Recognition quality is entirely your provider's.
Usage
Depend on this crate directly. The ocr-tesseract and ocr-paddle flags on the
pdfluent facade are reserved names that enable nothing — the facade does not
wire OCR at all, precisely because the local engines need C libraries.
use ;
Then call make_searchable(&mut doc, &engine, &config, render_fn).
For PaddleOCR or Tesseract instead of a cloud service, enable the matching feature and use the engine it provides — the rest of the call is identical, because they implement the same trait:
= { = "1", = ["paddle"] } # or ["tesseract"]
// Weights you already have on disk. Nothing is fetched.
let config = PaddleOcrConfig ;
let engine = with_config?;
// or Tesseract, which uses the system installation:
let engine = new?;
Model weights are never fetched behind your back
Constructing a PaddleOCR engine does not download anything. If the weights are not
in model_dir you get an error naming the missing files and the directory they
belong in — not a silent transfer of tens of megabytes from a host you did not choose.
If you do want this crate to fetch them, say so and pin what you expect:
use BTreeMap;
use ModelSource;
let mut digests = new;
digests.insert;
digests.insert;
digests.insert;
config.model_source = Verified ;
Each file is held in memory, hashed, and only written if it matches. A file with no
pinned digest is refused rather than fetched — something unverifiable should not
land on your disk at all. REFERENCE_MODEL_BASE_URL points at the public
third-party repository the ONNX exports come from; it is offered for convenience,
not as an endorsement, which is exactly why pinning is your call and not our
default.
For the full signature, see https://pdfluent.com/docs.
Licence
AGPL-3.0 or a commercial licence, at your option. The AGPL is the default and
the complete product: there is no licence key, no activation call and no tier,
and every feature works in every build. If you cannot accept the copyleft
obligation, the commercial licence is sold yearly and self-service at
pdfluent.com/sdk/pricing, in four options: Commercial (per
organisation), OEM Startup and OEM (per product), and Priority support (an
add-on). The two texts are LICENSE and LICENSE-COMMERCIAL in this crate.
Links
- Main crate: https://crates.io/crates/pdfluent
- Documentation: https://pdfluent.com/docs
- Pricing: https://pdfluent.com/sdk/pricing