Read the MediaBox, CropBox, and BleedBox from any PDF page. Convert between points and millimetres or inches for printing and layout workflows.
use pdfluent::PdfDocument;
fn main() -> pdfluent::Result<()> {
let doc = PdfDocument::open("file.pdf")?;
for i in 0..doc.page_count() {
let (w, h) = doc.page(i)?.dimensions();
println!("page {}: {} x {} pt", i + 1, w, h);
}
Ok(())
}Add the pdfluent crate to Cargo.toml.
[dependencies]
pdfluent = "1.0.0-beta.8"Open the document and iterate or index pages directly.
use pdfluent::PdfDocument;
let doc = PdfDocument::open("blueprint.pdf")?;
let page = doc.page(1)?; // first pageThe MediaBox defines the full physical extent of the page in PDF user units (points). 1 point = 1/72 inch.
let (width, height) = page.dimensions();
println!("Width: {:.2} pt", width);
println!("Height: {:.2} pt", height);CropBox is the visible page area. BleedBox is for print bleed. Both fall back to the MediaBox if not set.
// PDFluent exposes the effective page size via dimensions()
let (width, height) = page.dimensions();
println!("Page: {:.1} x {:.1} pt", width, height);PDF points convert to mm with factor 25.4/72 and to inches with factor 1/72.
fn pt_to_mm(pt: f64) -> f64 { pt * 25.4 / 72.0 }
fn pt_to_inch(pt: f64) -> f64 { pt / 72.0 }
let (w, h) = page.dimensions();
println!(
"Page size: {:.1} x {:.1} mm ({:.3} x {:.3} in)",
pt_to_mm(w), pt_to_mm(h), pt_to_inch(w), pt_to_inch(h),
);No JVM, no runtime, no DLL dependencies. Ships as a single native binary or WASM module.
Rust's ownership model prevents buffer overflows and use-after-free. No segfaults in PDF parsing.
Same code runs server-side, in Docker, on AWS Lambda, on Cloudflare Workers, or in the browser via WASM.