pub struct Pipeline { /* private fields */ }Expand description
A reusable PDF pipeline. The primary worker runs its models on every core, so a single-page / small / image / METS input is converted at full intra-op speed with no pool to load. A document with enough pages instead fans out across a pool of narrower workers processed concurrently. Both load lazily and are cached for reuse, so a one-shot conversion only pays for what it uses.
Implementations§
Source§impl Pipeline
impl Pipeline
Sourcepub fn new() -> Result<Self, PdfError>
pub fn new() -> Result<Self, PdfError>
Construct the pipeline. Models load lazily on first use (full-intra primary for serial inputs, the helper pool for multi-page PDFs), so nothing is loaded that a given document doesn’t need.
Sourcepub fn pages(self, range: Option<(usize, usize)>) -> Self
pub fn pages(self, range: Option<(usize, usize)>) -> Self
Convert only pages first..=last (1-based, like the page numbers a
PDF viewer shows — issue #80’s --pages A-B). Out-of-range pages are
skipped before rasterization, so the cost is proportional to the window,
not the document. last past the end of the document clamps; a window
that selects no pages at all (first beyond the last page) is an error
at convert time. None (the default) converts everything.
Sourcepub fn set_pages(&mut self, range: Option<(usize, usize)>)
pub fn set_pages(&mut self, range: Option<(usize, usize)>)
In-place variant of pages for a long-lived pipeline
(e.g. docling-serve’s warm instance) that applies a per-request window
without rebuilding — unlike the model switches, the window is pure
configuration. Set it before every conversion; it stays until changed.
Sourcepub fn ocr_lang(self, lang: Option<OcrLang>) -> Self
pub fn ocr_lang(self, lang: Option<OcrLang>) -> Self
OCR recognition language (see OcrLang): English by default, ch
for the multilingual docling-conformance model. None keeps the
process default (DOCLING_RS_OCR_LANG, else English). Set before the
first conversion; for a warm pipeline use
set_ocr_lang.
Sourcepub fn set_ocr_lang(&mut self, lang: Option<OcrLang>)
pub fn set_ocr_lang(&mut self, lang: Option<OcrLang>)
In-place variant of ocr_lang for a long-lived
pipeline (docling-serve’s warm instance). Unlike the page window this
is a model switch: any worker whose cached recognition model was
loaded for a different language drops it, to be lazily reloaded on the
next OCR-needing page (cheap — the rec models are ~10 MB).
Sourcepub fn enrichments(self, opts: EnrichmentOptions) -> Self
pub fn enrichments(self, opts: EnrichmentOptions) -> Self
Enable the opt-in enrichment passes (docling’s
do_picture_classification / do_code_enrichment /
do_formula_enrichment). Each enabled pass lazily loads its model on
the first matching region; a missing model warns once and is skipped.
Set before the first conversion (no effect on already-loaded workers).
Sourcepub fn no_table_former(self, disable: bool) -> Self
pub fn no_table_former(self, disable: bool) -> Self
Skip loading and running the TableFormer table-structure model. Table regions still get emitted, but reconstructed geometrically from cell positions instead of via the ONNX model’s predicted structure — faster (no model load, no per-table inference) at the cost of table fidelity. No effect if a worker is already loaded; set this before the first conversion.
Sourcepub fn no_ocr(self, disable: bool) -> Self
pub fn no_ocr(self, disable: bool) -> Self
Skip layout detection, OCR, and TableFormer entirely — no model load, no
inference of any kind. The PDF’s embedded text cells are grouped by line
and emitted as plain paragraphs in reading order: no headings, lists,
tables, code blocks, or pictures, since that structure comes from the
layout model. The fastest possible PDF path, but pages with no embedded
text layer (scanned/image-only PDFs) yield no text at all — convert those
without this flag. Implies no_table_former. No effect if a worker is
already loaded; set this before the first conversion.
Sourcepub fn force_full_page_ocr(self, force: bool) -> Self
pub fn force_full_page_ocr(self, force: bool) -> Self
OCR every page from its rendered image even when the page carries an
embedded text layer — docling’s force_full_page_ocr. The escape hatch
for text layers that exist but lie: broken encodings, subset fonts with
garbage mappings, a scanned form with a few typed-in fields. Ignored
when no_ocr is set, mirroring docling (there
force_full_page_ocr is a sub-option of do_ocr).
Sourcepub fn warm_up(&mut self) -> Result<(), PdfError>
pub fn warm_up(&mut self) -> Result<(), PdfError>
Eagerly load the models (the full-intra serial worker: layout + OCR, and
the shared TableFormer unless disabled) so the first conversion doesn’t pay
the load cost. Idempotent; respects no_ocr / no_table_former (with
no_ocr there is nothing to load). The docling.rs analogue of docling’s
DocumentConverter.initialize_pipeline.
Sourcepub fn convert(
&mut self,
bytes: &[u8],
password: Option<&str>,
name: &str,
) -> Result<DoclingDocument, PdfError>
pub fn convert( &mut self, bytes: &[u8], password: Option<&str>, name: &str, ) -> Result<DoclingDocument, PdfError>
Convert a PDF (bytes) to a DoclingDocument. A document with fewer than
parallel_min pages (or a pool size of 1) streams through the full-intra
primary; a larger one renders on this thread (pdfium is not thread-safe) and
fans the pages out across the worker pool, reassembled in page order so the
output is byte-identical to the serial path.
Sourcepub fn convert_streaming<F>(
&mut self,
bytes: &[u8],
password: Option<&str>,
name: &str,
emit: F,
) -> Result<(), PdfError>
pub fn convert_streaming<F>( &mut self, bytes: &[u8], password: Option<&str>, name: &str, emit: F, ) -> Result<(), PdfError>
Convert a PDF in streaming mode: emit is called with each finalized,
in-document-order batch of nodes (and that span’s recovered links) as pages
complete, so a caller can serialize Markdown page by page instead of waiting
for the whole document. The batches are exactly the buffered convert’s
nodes, split at safe block boundaries by [assemble::StreamAssembler] — the
parallel path reorders pages back into document order before emitting, so
the output is identical regardless of worker scheduling.
emit runs on the calling thread (never a worker), so it needn’t be Send
and its backpressure throttles the whole pipeline. Returning Err from
emit aborts the conversion with that error.
Sourcepub fn convert_image(
&mut self,
bytes: &[u8],
name: &str,
) -> Result<DoclingDocument, PdfError>
pub fn convert_image( &mut self, bytes: &[u8], name: &str, ) -> Result<DoclingDocument, PdfError>
Convert a standalone image (PNG/JPEG/TIFF/WebP/…) as a single page — docling routes images through the same layout+OCR pipeline as a PDF page.
Auto Trait Implementations§
impl !RefUnwindSafe for Pipeline
impl !UnwindSafe for Pipeline
impl Freeze for Pipeline
impl Send for Pipeline
impl Sync for Pipeline
impl Unpin for Pipeline
impl UnsafeUnpin for Pipeline
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more