Skip to main content

DocumentConverter

Struct DocumentConverter 

Source
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

Source

pub fn new() -> Self

A converter that accepts every supported format.

Source

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.

Source

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.

Source

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).

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn convert( &self, source: SourceDocument, ) -> Result<ConversionResult, ConversionError>

Convert a single source document.

Trait Implementations§

Source§

impl Clone for DocumentConverter

Source§

fn clone(&self) -> DocumentConverter

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for DocumentConverter

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for DocumentConverter

Source§

fn default() -> DocumentConverter

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<F, T> IntoSample<T> for F
where T: FromSample<F>,

Source§

fn into_sample(self) -> T

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<R, P> ReadPrimitive<R> for P
where R: Read + ReadEndian<P>, P: Default,

Source§

fn read_from_little_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_little_endian().
Source§

fn read_from_big_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_big_endian().
Source§

fn read_from_native_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_native_endian().
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V