Render small preview images of every page in a PDF. Set a fixed width or height and PDFluent calculates the other dimension automatically.
use pdfluent::prelude::*;
fn main() -> Result<()> {
let doc = PdfDocument::open("slides.pdf")?;
// Render all pages as PNG thumbnails at 72 DPI.
let report = doc.to_images(
"thumb_{page}.png",
ToImagesOptions::new()
.with_dpi(72)
.with_format(ImageFormat::Png),
)?;
println!("wrote {} thumbnails", report.paths.len());
Ok(())
}Load the document.
use pdfluent::prelude::*;
let doc = PdfDocument::open("slides.pdf")?;72 DPI is typical for thumbnails; for crisper previews, go up to 150 DPI.
let opts = ToImagesOptions::new()
.with_dpi(72)
.with_format(ImageFormat::Png);The {page} marker in the filename pattern is substituted with the 1-based page number.
let report = doc.to_images("thumb_{page}.png", opts)?;
for path in &report.paths {
println!("wrote {}", path.display());
}Limit the range with with_pages(from, to) using 1-based inclusive bounds.
let opts = ToImagesOptions::new()
.with_dpi(72)
.with_pages(1, 1);
let _ = doc.to_images("cover.png", opts)?;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.