Render, generate, edit, and extract PDF content

This guide shows developers how to perform core PDF operations with PDFluent. It covers rendering PDFs to images, editing documents, and processing annotations.

Render PDFs to images, anywhere.

Convert PDF pages to PNG, JPEG, or WebP with sub-pixel accuracy. Runs server-side, in Lambda, or via WASM.

rust
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(())
}

Generate PDF thumbnails at scale.

Convert first pages or any pages to JPEG/PNG thumbnails. Batch process document libraries without a display server.

rust
use pdfluent::{PdfDocument, ImageFormat};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let doc = PdfDocument::open("document.pdf")?;

    for i in 0..doc.page_count() {
        let png = doc.render_page(i, 72, ImageFormat::Png)?;
        std::fs::write(format!("thumb-{}.png", i + 1), png)?;
    }
    Ok(())
}

Run PDF processing in the browser.

PDFluent compiles to WASM. Process PDFs client-side without uploading files to a server.

rust
const bytes = new Uint8Array(await file.arrayBuffer());
const doc = PdfDoc.open(bytes);

// renderPage returns raw RGBA with an 8-byte header: width, height, then pixels.
const raw = doc.renderPage(0, 1.5);
const view = new DataView(raw.buffer);
const w = view.getUint32(0, true);
const h = view.getUint32(4, true);
const imageData = new ImageData(new Uint8ClampedArray(raw.slice(8)), w, h);
ctx.putImageData(imageData, 0, 0);

Edit existing PDFs in Rust.

Replace text, stamp, fill forms and update metadata on documents that already exist.

rust
use pdfluent::{PdfDocument, ReplaceOptions, TextQuery, WatermarkOptions};

fn approve(input: &[u8]) -> pdfluent::Result<Vec<u8>> {
    let mut doc = PdfDocument::from_bytes(input)?;

    // Rewrite text that is already on the page, in its own font
    doc.replace_text(
        TextQuery::exact("Status: pending"),
        "Status: approved",
        ReplaceOptions::default(),
    )?;

    // Stamp every page
    doc.add_watermark(
        "APPROVED",
        WatermarkOptions::centered().opacity(0.3),
    )?;

    // Fill a field and make the value permanent
    doc.form_mut().set_text("approver", "Finance Team")?;
    doc.flatten_forms()?;

    // Update document metadata
    doc.metadata_mut()
        .set_author("Finance Team")
        .set_keywords(&["approved", "processed", "2026"])
        .commit()?;

    doc.to_bytes()
}

Add watermarks and stamps to PDFs.

Apply text watermarks, image overlays, and stamps to single pages or entire documents. Batch watermark with per-document variable data.

rust
use pdfluent::{PdfDocument, WatermarkOptions};

fn main() -> pdfluent::Result<()> {
    let mut doc = PdfDocument::open("document.pdf")?;

    let opts = WatermarkOptions::centered()
        .font_size(64.0)
        .rotated(45.0)
        .opacity(0.15)
        .color(0.6, 0.0, 0.0);

    doc.add_watermark("CONFIDENTIAL", opts)?;
    doc.save("watermarked.pdf")?;
    Ok(())
}

Text extraction. Done right.

PDF text extraction with 97.5% pass rate. Preserve layout, reading order, and font metadata.

rust
use pdfluent::PdfDocument;

fn main() -> pdfluent::Result<()> {
    let doc = PdfDocument::open("document.pdf")?;

    // Plain text
    println!("{}", doc.extract_text()?);

    // Positioned text blocks: text + bounding box + page
    for block in doc.text_with_layout()? {
        println!("p{} {:?} {}", block.page, block.bbox, block.text);
    }
    Ok(())
}