Rasterise any PDF page to a PNG image at a chosen DPI. Works headless with no display server required.
use pdfluent::prelude::*;
fn main() -> Result<()> {
let doc = PdfDocument::open("document.pdf")?;
let report = doc.to_images(
"page_{page}.png",
ToImagesOptions::new()
.with_dpi(150)
.with_format(ImageFormat::Png),
)?;
println!("rendered {} pages", report.paths.len());
Ok(())
}Open the document. Rendering is a document-level operation in PDFluent: you choose the output pattern and a page range.
use pdfluent::prelude::*;
let doc = PdfDocument::open("slides.pdf")?;ToImagesOptions::new() defaults to 150 DPI and PNG output. Override DPI and format to taste. For sharp screen previews 150 DPI is fine; print-quality output is 300 DPI.
let opts = ToImagesOptions::new()
.with_dpi(150)
.with_format(ImageFormat::Png);Use .with_pages(from, to) with 1-based inclusive bounds. Omit to render every page.
let opts = ToImagesOptions::new()
.with_dpi(150)
.with_pages(1, 3); // pages 1, 2, 3Pass a filename pattern. The {page} placeholder is substituted with the 1-based page number. If the pattern has no {page}, PDFluent inserts _N before the extension.
let report = doc.to_images("page_{page}.png", opts)?;
for path in &report.paths {
println!("wrote {}", path.display());
}Change the format via .with_format(ImageFormat::Jpeg). JPEG does not carry transparency, so RGBA pixels are flattened to RGB before encoding.
use pdfluent::prelude::*;
let doc = PdfDocument::open("document.pdf")?;
doc.to_images(
"thumb_{page}.jpg",
ToImagesOptions::new()
.with_dpi(72)
.with_format(ImageFormat::Jpeg),
)?;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.