| Crates.io | pdfium-bind |
| lib.rs | pdfium-bind |
| version | 0.1.0 |
| created_at | 2025-12-26 04:01:06.570532+00 |
| updated_at | 2025-12-26 04:01:06.570532+00 |
| description | Rust bindings for PDFium with vendored prebuilt binaries |
| homepage | https://github.com/houqp/kiorg |
| repository | https://github.com/houqp/kiorg |
| max_upload_size | |
| id | 2005247 |
| size | 63,015 |
Rust FFI bindings and a high-level wrapper for PDFium.
Designed for ease of distribution: This crate eliminates the need for users to manually install PDFium on their systems. It embeds prebuilt PDFium binaries directly into your executable.
dynamic (Default): Embeds the PDFium dynamic library within your binary. At runtime, it extracts the library to a temporary file and loads it.static: Links PDFium statically at build time.You can override the PDFium library and headers used during build by setting the following environment variables:
PDFIUM_STATIC_LIB_PATH: Path to libpdfium.a (for static feature).PDFIUM_DYNAMIC_LIB_PATH: Path to the dynamic library (e.g., .so, .dylib, or .dll) (for dynamic feature).PDFIUM_INCLUDE_PATH: Path to the directory containing PDFium headers (required if any of the above are set).If these variables are not set, the build script will automatically download the appropriate PDFium binary for your platform.
use pdfium_bind::PdfDocument;
use std::path::Path;
fn main() -> Result<(), String> {
// Open a PDF document
let path = Path::new("example.pdf");
let doc = PdfDocument::open(path)?;
// Get page count
let count = doc.page_count();
println!("Page count: {}", count);
// Get PDF version
println!("PDF version: {}", doc.get_pdf_version());
// Get metadata
if let Some(title) = doc.get_metadata_value("Title") {
println!("Title: {}", title);
}
// Render a page (e.g., page 0 at 300 DPI)
// Returns (pixel_data, width, height) where pixel_data is RGBA
let (pixels, width, height) = doc.render_page(0, 300.0)?;
println!("Rendered page size: {}x{}", width, height);
Ok(())
}
When using the dynamic feature on Windows, the PDFium DLL is extracted to a temporary location. If you want to ensure this file is cleaned up when your application exits, you can call:
pdfium_bind::cleanup_cache();
On Unix platforms, the temporary file is deleted immediately after being loaded into memory.
The crate automatically downloads pre-built PDFium binaries for supported platforms: