Skip to content
Tom edited this page May 13, 2026 · 3 revisions

pdf-raster

Pure Rust PDF → 8-bit greyscale pixel pipeline, built for OCR.

What it does

pdf-raster converts PDF pages into raw 8-bit greyscale pixel buffers with no Poppler, no subprocesses, and no Leptonica in the render path. Each page comes back as a RenderedPage containing a flat Vec<u8> of pixels, ready to hand directly to Tesseract, ocrs, Google Cloud Vision, GPT-5, Mistral, or any other OCR/vision engine. GPU acceleration is available via CUDA (nvJPEG, AA fill, ICC CLUT) and Vulkan (cross-vendor, AMD/Intel/Apple).

Quick start

[dependencies]
pdf_raster = { git = "https://github.com/pthomasfournet/pdf-raster", tag = "v0.8.0" }
use pdf_raster::{raster_pdf, RasterOptions};

let opts = RasterOptions {
    dpi: 300.0,
    first_page: 1,
    last_page: u32::MAX,
    deskew: false,
    pages: None,
};

for (page_num, result) in raster_pdf("document.pdf", opts) {
    let page = result?;
    println!(
        "page {}: {}x{} @ {:.0} dpi, {} bytes",
        page_num,
        page.width,
        page.height,
        page.effective_dpi,
        page.pixels.len()
    );
    // page.pixels is a flat Vec<u8> of 8-bit greyscale samples,
    // row-major, width x height bytes total.
}

Always use page.effective_dpi, not the dpi you passed in — it accounts for PDF UserUnit scaling, which can silently change the true resolution.

Integration guides

Guide Engines
OCR Integration Tesseract (leptess), ocrs
LLM Vision OCR Integration Google Cloud Vision, GPT-5, Mistral

API surface

Symbol Description
raster_pdf(path, opts) Iterator yielding (page_num, Result<RenderedPage>)
render_channel(path, opts, capacity) Channel-based pipeline for concurrent OCR workers
RasterOptions dpi, first_page, last_page, deskew, pages
RenderedPage pixels, width, height, dpi, effective_dpi

render_channel is the better choice when you have a pool of OCR workers — it keeps the rasterizer and workers running concurrently rather than serialising them.

Adding the dependency

[dependencies]
pdf_raster = { git = "https://github.com/pthomasfournet/pdf-raster", tag = "v0.8.0" }

The crate is GitHub-distributed only (not published to crates.io).

Further reading

  • Main repository README — build instructions, GPU feature flags, benchmark results, and the full crate map.

Pure Rust PDF → pixels pipeline. No Poppler. No subprocesses.


🚀 Getting Started


🔌 Integration Guides


📊 Reference


🔗 Links

Clone this wiki locally