pdfmuse-core 0.1.0

Deterministic PDF/DOCX parser core (pure Rust). The value core of pdfmuse.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
//! JSON rendering of the full IR.

use crate::ir::Document;

/// Serialize the entire [`Document`] to pretty-printed JSON.
///
/// The IR derives `Serialize` and contains only serializable types, so the
/// pretty path cannot realistically fail; on the impossible error we fall back
/// to compact `to_string` rather than panic.
pub fn to_json(doc: &Document) -> String {
    serde_json::to_string_pretty(doc)
        .or_else(|_| serde_json::to_string(doc))
        .unwrap_or_default()
}