docling/lib.rs
1//! docling.rs: a Rust port of [docling](https://github.com/docling-project/docling).
2//!
3//! The public surface mirrors the Python SDK, kept deliberately small:
4//!
5//! ```no_run
6//! use docling::{DocumentConverter, SourceDocument};
7//!
8//! let converter = DocumentConverter::new();
9//! let result = converter
10//! .convert(SourceDocument::from_file("input.md").unwrap())
11//! .unwrap();
12//! println!("{}", result.document.export_to_markdown());
13//! ```
14//!
15//! For the PDF/image ML pipeline (pdfium + layout/TableFormer/OCR ONNX), reuse a
16//! [`Pipeline`] across documents to amortize model loading, instead of the
17//! per-call [`DocumentConverter`]. Deploying as a service: `examples/Dockerfile`
18//! is a 3-stage build that bakes the binary, native libs, and exported models
19//! (including the KV-cached TableFormer decoder) into a slim, Python-free runtime
20//! image — see the "Deploy in a container" section of the README.
21//!
22//! See `docs/MIGRATION.md` for the architecture, format-by-format parity
23//! status, and how conformance against Python docling is measured.
24
25pub mod chunks;
26mod converter;
27pub mod dclx;
28mod error;
29mod format;
30mod result;
31mod source;
32#[cfg(feature = "pdf")]
33mod stream;
34#[cfg(feature = "vlm")]
35pub mod vlm;
36
37pub mod backend;
38#[cfg(feature = "asr")]
39pub mod video;
40
41pub use converter::{parse_page_range, DocumentConverter, DEFAULT_VIDEO_FRAMES};
42pub use error::ConversionError;
43pub use format::InputFormat;
44pub use result::{ConversionResult, ConversionStatus, ErrorItem};
45pub use source::SourceDocument;
46#[cfg(feature = "pdf")]
47pub use stream::MarkdownStream;
48
49// Re-export the core model so callers only need the one crate, and so
50// `result.document.export_to_markdown()` works without an extra import.
51pub use docling_core::base64;
52pub use docling_core::chunker;
53pub use docling_core::pandoc;
54pub use docling_core::{
55 ConfidenceReport, ContentLayer, ContentLayers, DocItemLabel, DoclingDocument,
56 HtmlExportOptions, ImageMode, MarkdownStreamer, Node, PictureImage, QualityGrade, Table,
57};
58
59// The reusable PDF/image pipeline (models loaded once, reused across documents),
60// for callers that convert many files or want a warm, startup-excluded measurement.
61#[cfg(feature = "pdf")]
62pub use docling_pdf::{
63 model_inventory, page_count as pdf_page_count, render_pages as render_pdf_pages,
64 tesseract_lang_arg, EnrichmentOptions, HeadingHierarchyOptions, ImageOutput, ModelEntry,
65 OcrEngine, OcrLang, OcrMode, Pipeline, RenderedPage,
66};
67// The pure-Rust text-layer extraction (no pdfium, no models) — compiled with
68// either PDF feature. The CLI uses it as the `--no-ocr` fallback when the
69// runtime assets are missing (launch blocker: a bare `cargo install` ships
70// neither pdfium nor the models).
71#[cfg(any(feature = "pdf", feature = "pdf-text"))]
72pub use docling_pdf::convert_text_layer_pages as pdf_text_layer_pages;
73
74/// Which PDF conversion this build compiled in: the full ML pipeline (`pdf`
75/// feature), the pure-Rust text-layer path (`pdf-text`, the wasm32 build), or
76/// neither. Compile-time facts, exported so downstream crates (whose own
77/// features can't see this crate's) can branch — e.g. docling-wasm's host
78/// tests, where workspace feature unification may pull `pdf` in.
79pub const PDF_ML_COMPILED: bool = cfg!(feature = "pdf");
80/// True when the `pdf-text` text-layer-only PDF path is compiled in.
81pub const PDF_TEXT_COMPILED: bool = cfg!(feature = "pdf-text");
82
83/// Stand-in for `docling_pdf::EnrichmentOptions` when the `pdf` feature is
84/// off: the `DocumentConverter` builder methods keep compiling (and stay
85/// inert — the formats these flags affect are rejected at convert time).
86#[cfg(not(feature = "pdf"))]
87#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
88pub struct EnrichmentOptions {
89 /// Classify each picture with DocumentFigureClassifier (26 classes).
90 pub picture_classification: bool,
91 /// Rewrite code blocks (and detect their language) with CodeFormulaV2.
92 pub code: bool,
93 /// Decode display formulas to LaTeX with CodeFormulaV2.
94 pub formula: bool,
95}