pub struct DocumentConverter { /* private fields */ }Expand description
Routes a SourceDocument to the backend for its format and returns a
ConversionResult.
The Rust analogue of docling.document_converter.DocumentConverter. In
Phase 0 the format→backend dispatch is a direct match; the Python notion of
per-format FormatOption (backend + pipeline + options) arrives with the
PDF/ML pipeline in a later phase.
Implementations§
Source§impl DocumentConverter
impl DocumentConverter
Sourcepub fn with_allowed_formats(
formats: impl IntoIterator<Item = InputFormat>,
) -> Self
pub fn with_allowed_formats( formats: impl IntoIterator<Item = InputFormat>, ) -> Self
A converter restricted to an explicit set of formats. Sources of any
other format are rejected with ConversionError::UnsupportedFormat.
Sourcepub fn strict(self, strict: bool) -> Self
pub fn strict(self, strict: bool) -> Self
Select the Markdown export mode for documents this converter produces.
false (default) makes crate::DoclingDocument::export_to_markdown
reproduce docling’s legacy output byte-for-byte; true makes it emit
cleaner, more conformant Markdown (code-fence languages preserved, no
inline-run spacing artifacts, no entity re-escaping). Rust-only — Python
docling has no such switch.
Sourcepub fn fetch_images(self, fetch: bool) -> Self
pub fn fetch_images(self, fetch: bool) -> Self
Fetch and embed external <img> images for HTML/EPUB sources.
Off by default (matching docling’s enable_*_fetch=False), so output is
unchanged unless you opt in. When on, the HTML/EPUB backends resolve each
<img src> — data: URIs, local files (relative to the source file’s
directory), http(s) URLs, and EPUB archive entries — and embed the
bytes, so they survive into JSON ImageRefs and
crate::DoclingDocument::export_to_markdown_with_images.
Remote http(s) URLs are fetched over the network; enable only for input
you trust (it can otherwise be used to make the process issue requests).
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 for PDF/image/METS sources.
Off by default. When enabled, table regions are still detected and
emitted, but their structure is reconstructed geometrically from cell
positions instead of the ONNX model’s predicted structure — no model
load and no per-table inference, at the cost of table fidelity. Useful
when parsing speed matters more than exact table structure, especially
with convert_streaming.
Sourcepub fn no_ocr(self, disable: bool) -> Self
pub fn no_ocr(self, disable: bool) -> Self
Skip layout detection, OCR, and TableFormer entirely for PDF/image/METS sources — no model load, no inference of any kind.
Off by default. When enabled, 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.
Sourcepub fn do_picture_classification(self, enable: bool) -> Self
pub fn do_picture_classification(self, enable: bool) -> Self
Classify each detected picture with the DocumentFigureClassifier model
(docling’s do_picture_classification). Off by default.
The full 26-class prediction distribution (bar_chart, logo, signature,
…) lands on the picture item and is serialized into the docling JSON as
the classification annotation plus the meta.classification field.
Markdown output is unaffected. Needs models/picture_classifier.onnx
(fetched by scripts/install/download_dependencies.sh); a missing
model warns once and skips classification.
Sourcepub fn do_code_enrichment(self, enable: bool) -> Self
pub fn do_code_enrichment(self, enable: bool) -> Self
Rewrite detected code blocks with the CodeFormulaV2 VLM (docling’s
do_code_enrichment). Off by default.
The model re-reads the code crop at ~120 dpi, emits the clean source
text (line breaks included) and identifies the language, which lands in
the JSON code_language field. Needs the models/code_formula/ graphs
(fetched by scripts/install/download_dependencies.sh); a missing
model warns once and leaves the block as extracted.
Sourcepub fn do_formula_enrichment(self, enable: bool) -> Self
pub fn do_formula_enrichment(self, enable: bool) -> Self
Decode display formulas to LaTeX with the CodeFormulaV2 VLM (docling’s
do_formula_enrichment). Off by default.
An enriched formula renders as $$latex$$ in Markdown and as a
formula text item in the JSON, replacing the
<!-- formula-not-decoded --> placeholder. Same model artifacts as
do_code_enrichment.
Sourcepub fn use_web_browser(self, enable: bool) -> Self
pub fn use_web_browser(self, enable: bool) -> Self
Pre-render HTML-routing input in a headless browser before parsing.
Off by default. When enabled, HTML sources — and MHTML/EPUB, which
assemble HTML from their archives — are loaded in the system Chromium
(driven from Rust over the DevTools protocol — no Node/Playwright) so the
CSS cascade is resolved: elements the browser computes as display:none
(e.g. a stylesheet-collapsed nav menu) are removed before the normal HTML
backend runs. This is the one behaviour a pure-Rust parse can’t reproduce;
everything else (structure, tables, KVP, formatting) is still handled in
Rust on the cleaned HTML.
Requires the crate’s web-browser Cargo feature; without it, converting
an HTML source with this enabled returns ConversionError::Browser.
Sourcepub fn convert_streaming(
&self,
source: SourceDocument,
) -> Result<MarkdownStream, ConversionError>
pub fn convert_streaming( &self, source: SourceDocument, ) -> Result<MarkdownStream, ConversionError>
Convert a source document to Markdown incrementally, returning an iterator of Markdown chunks (with picture placeholders).
Concatenating every Ok chunk reproduces
convert(...).document.export_to_markdown()
byte-for-byte. The win is for PDF, whose pages are processed in parallel:
each page’s Markdown is emitted in document order as soon as it is ready, so
output starts before the whole document is converted. Other formats build
their document up front and stream it through the same interface.
Streaming is Markdown-only — JSON needs the whole node tree, so there is no
streaming JSON. The conversion runs on a background thread; dropping the
returned MarkdownStream cancels it.
Sourcepub fn convert_streaming_images(
&self,
source: SourceDocument,
image_mode: ImageMode,
) -> Result<MarkdownStream, ConversionError>
pub fn convert_streaming_images( &self, source: SourceDocument, image_mode: ImageMode, ) -> Result<MarkdownStream, ConversionError>
Like convert_streaming but with an explicit
picture ImageMode. Only ImageMode::Placeholder and
ImageMode::Embedded are streamable; ImageMode::Referenced writes
separate image files and needs the buffered
DoclingDocument::export_to_markdown_with_images path, so it is rejected
here.
Sourcepub fn convert(
&self,
source: SourceDocument,
) -> Result<ConversionResult, ConversionError>
pub fn convert( &self, source: SourceDocument, ) -> Result<ConversionResult, ConversionError>
Convert a single source document.
Trait Implementations§
Source§impl Clone for DocumentConverter
impl Clone for DocumentConverter
Source§fn clone(&self) -> DocumentConverter
fn clone(&self) -> DocumentConverter
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for DocumentConverter
impl Debug for DocumentConverter
Source§impl Default for DocumentConverter
impl Default for DocumentConverter
Source§fn default() -> DocumentConverter
fn default() -> DocumentConverter
Auto Trait Implementations§
impl Freeze for DocumentConverter
impl RefUnwindSafe for DocumentConverter
impl Send for DocumentConverter
impl Sync for DocumentConverter
impl Unpin for DocumentConverter
impl UnsafeUnpin for DocumentConverter
impl UnwindSafe for DocumentConverter
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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 moreSource§impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
fn into_sample(self) -> T
Source§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian().