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 archive;
26pub mod chunks;
27mod converter;
28pub mod dclx;
29pub mod email_attachments;
30mod error;
31mod format;
32pub mod options;
33mod result;
34mod sniff;
35mod source;
36#[cfg(feature = "pdf")]
37mod stream;
38#[cfg(feature = "vlm")]
39pub mod vlm;
40
41pub mod backend;
42#[cfg(feature = "asr")]
43pub mod video;
44
45pub use archive::{ArchiveLimits, ArchiveOutcome};
46pub use converter::{parse_page_range, DocumentConverter, DEFAULT_VIDEO_FRAMES};
47pub use email_attachments::{EmailAttachmentInfo, EmailAttachments};
48pub use error::{ConversionError, EncryptionError};
49pub use format::{InputFormat, OUTPUT_FORMATS};
50pub use options::{
51 cli_flag, merge_options, ConvertOptions, OptionInfo, OptionsError, PipelineKind, OPTIONS,
52};
53pub use result::{ConversionResult, ConversionStatus, ErrorItem};
54pub use source::SourceDocument;
55#[cfg(feature = "pdf")]
56pub use stream::MarkdownStream;
57
58// Re-export the core model so callers only need the one crate, and so
59// `result.document.export_to_markdown()` works without an extra import.
60pub use docling_core::base64;
61pub use docling_core::chunker;
62pub use docling_core::pandoc;
63pub use docling_core::{
64 ConfidenceReport, ContentLayer, ContentLayers, DocItemLabel, DoclingDocument,
65 HtmlExportOptions, ImageMode, MarkdownExportOptions, MarkdownStreamer, Node, PictureImage,
66 QualityGrade, Table,
67};
68
69// The reusable PDF/image pipeline (models loaded once, reused across documents),
70// for callers that convert many files or want a warm, startup-excluded measurement.
71#[cfg(feature = "pdf")]
72pub use docling_pdf::{
73 model_inventory, page_count as pdf_page_count, render_pages as render_pdf_pages,
74 tesseract_lang_arg, EnrichmentOptions, HeadingHierarchyOptions, ImageOutput, ModelEntry,
75 OcrEngine, OcrLang, OcrMode, PdfError, Pipeline, RenderedPage,
76};
77// The pure-Rust text-layer extraction (no pdfium, no models) — compiled with
78// either PDF feature. The CLI uses it as the `--text-layer-only` fallback when the
79// runtime assets are missing (launch blocker: a bare `cargo install` ships
80// neither pdfium nor the models).
81#[cfg(any(feature = "pdf", feature = "pdf-text"))]
82pub use docling_pdf::convert_text_layer_pages as pdf_text_layer_pages;
83
84/// Which PDF conversion this build compiled in: the full ML pipeline (`pdf`
85/// feature), the pure-Rust text-layer path (`pdf-text`, the wasm32 build), or
86/// neither. Compile-time facts, exported so downstream crates (whose own
87/// features can't see this crate's) can branch — e.g. docling-wasm's host
88/// tests, where workspace feature unification may pull `pdf` in.
89pub const PDF_ML_COMPILED: bool = cfg!(feature = "pdf");
90/// True when the `pdf-text` text-layer-only PDF path is compiled in.
91pub const PDF_TEXT_COMPILED: bool = cfg!(feature = "pdf-text");
92
93/// Stand-in for `docling_pdf::EnrichmentOptions` when the `pdf` feature is
94/// off: the `DocumentConverter` builder methods keep compiling (and stay
95/// inert — the formats these flags affect are rejected at convert time).
96#[cfg(not(feature = "pdf"))]
97#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
98pub struct EnrichmentOptions {
99 /// Classify each picture with DocumentFigureClassifier (26 classes).
100 pub picture_classification: bool,
101 /// Rewrite code blocks (and detect their language) with CodeFormulaV2.
102 pub code: bool,
103 /// Decode display formulas to LaTeX with CodeFormulaV2.
104 pub formula: bool,
105}