use pdfium_bind::{Document, Library};

fn main() {
    let _lib = Library::init();

    let path = std::env::args().nth(1).expect("usage: render_page <file.pdf> [page] [dpi]");
    let page_index: u32 = std::env::args().nth(2).and_then(|s| s.parse().ok()).unwrap_or(0);
    let dpi: f32 = std::env::args().nth(3).and_then(|s| s.parse().ok()).unwrap_or(150.0);

    let doc = Document::open(&path).unwrap();
    println!("opened {} ({} pages)", path, doc.page_count());

    let page = doc.page(page_index).unwrap();
    println!(
        "page {}: {:.1} × {:.1} pt",
        page_index,
        page.width(),
        page.height()
    );

    let result = page.render(dpi).unwrap();
    println!(
        "rendered: {}×{} px, {} bytes (stride={})",
        result.width,
        result.height,
        result.data.len(),
        result.stride
    );
}
