Convert PDF pages to PNG, JPEG, or WebP with sub-pixel accuracy. Runs server-side, in Lambda, or via WASM.
use pdfluent::{PdfDocument, ImageFormat};
fn main() -> Result<(), Box<dyn std::error::Error>> {
let doc = PdfDocument::open("document.pdf")?;
let png = doc.render_page(0, 150, ImageFormat::Png)?;
std::fs::write("page-1.png", png)?;
Ok(())
}Run cargo add [email protected] to get started.
Render at any DPI from 72 to 600. Set DPI per-page or globally. Output pixel dimensions scale exactly with the DPI value you specify.
Outputs sRGB by default. Supports CMYK-to-RGB conversion and grayscale rendering. Color profiles embedded in the PDF are honored during conversion.
Render a specific crop box region instead of the full page. Pass a rectangle in PDF user space coordinates. Useful for extracting figures or thumbnails from a section of a page.
The same render API compiles to WebAssembly. Run PDF-to-image conversion in the browser or in Cloudflare Workers without any server round-trip.
Render all pages in a loop or in parallel using Rayon. Each call to render_page is stateless and thread-safe. Typical throughput is 80-120 pages per second at 96 DPI on a 4-core machine.
PDFluent does not call X11, Wayland, CoreGraphics, or any OS display API. It works on headless Linux servers, in containers, and in Lambda without extra configuration.