image_fidelity/
image_fidelity.rs1use rust_docx::{build_doc_model, package_to_bytes, parse_document_bytes, try_serialize_doc_model};
2
3fn main() -> Result<(), Box<dyn std::error::Error>> {
4 let mut args = std::env::args_os().skip(1);
5 let input = args.next().ok_or("Input document is required")?;
6 let output = args.next().ok_or("Output model path is required")?;
7 let package = parse_document_bytes(&std::fs::read(input)?)?;
8 let model = build_doc_model(&package);
9 std::fs::write(output, serde_json::to_vec(&model)?)?;
10 if let Some(output) = args.next() {
11 let mut rebuilt = model;
12 for node in &mut rebuilt.nodes {
13 if let rust_docx::DocNode::Paragraph(paragraph) = node {
14 paragraph.source_xml = None;
15 paragraph.source_text_patch = None;
16 }
17 }
18 let exported = try_serialize_doc_model(&rebuilt, Some(&package))?;
19 std::fs::write(output, package_to_bytes(&exported)?)?;
20 }
21 Ok(())
22}