Skip to main content

dump_stages/
dump_stages.rs

1//! Dump preprocessing stages for render-parity debugging against docling.
2//! Usage: `... --example dump_stages -- file.pdf <out_dir>`
3use fleischwolf_pdf::PdfDocument;
4use image::imageops;
5
6fn main() {
7    let path = std::env::args().nth(1).expect("pdf");
8    let out = std::env::args().nth(2).expect("out_dir");
9    let bytes = std::fs::read(&path).expect("read");
10    let doc = PdfDocument::open(&bytes, None).expect("open");
11    let page = &doc.pages[0];
12    page.image.save(format!("{out}/my_page.png")).unwrap();
13    println!("my_page: {}x{}", page.image.width(), page.image.height());
14
15    let sf = 1024.0 / page.image.height() as f32;
16    let pw = (page.image.width() as f32 * sf).round() as u32;
17    let p1024 = imageops::thumbnail(&page.image, pw, 1024);
18    p1024.save(format!("{out}/my_p1024.png")).unwrap();
19    println!("my_p1024: {}x{}", p1024.width(), p1024.height());
20}