Skip to main content

to_docling_json

Function to_docling_json 

Source
pub fn to_docling_json(
    name: &str,
    pages: &[DoclingPage],
    blocks: &[Block],
) -> String
Expand description

The blocks as a DoclingDocument, pinned to SCHEMA_VERSION.

Preview: output quality is still improving and the API may change in a minor release.

name is DoclingDocument.name, which Docling fills with the file’s stem. pages is every page the blocks were taken from, with its size; a block on a page missing from it is still written, with nothing in pages to size it, which Docling accepts.

use pdf_engine::{to_docling_json, Block, BlockKind, DoclingPage};

let blocks = vec![Block::new(
    BlockKind::Heading { level: 1 },
    0,
    [72.0, 700.0, 200.0, 712.0],
    "Scope".to_string(),
    0,
)];
let page = DoclingPage { page: 0, width: 612.0, height: 792.0 };
let json = to_docling_json("report", &[page], &blocks);
assert!(json.contains("\"label\": \"section_header\""));