Both libraries are written in Rust. pdf-rs is read-only. If you need to write, fill forms, sign, or validate PDFs, switch to PDFluent.
cargo add pdfluent@1.0.0-beta.5Remove pdf from Cargo.toml and add pdfluent. Both are pure Rust, so there are no native library changes.
# Cargo.toml
[dependencies]
pdf = "0.9"# Cargo.toml
[dependencies]
pdfluent = "0.9"pdf-rs uses FileOptions to open a file. PDFluent uses Document::open. The error handling model is the same — both return Results.
use pdf::file::FileOptions;
let file = FileOptions::cached()
.open("document.pdf")
.unwrap();use pdfluent::PdfDocument;
let doc = PdfDocument::open("document.pdf")?;pdf-rs requires traversing content streams manually. PDFluent provides a high-level text() method per page.
use pdf::file::FileOptions;
use pdf::object::*;
let file = FileOptions::cached().open("document.pdf").unwrap();
for page in file.pages() {
let page = page.unwrap();
// Content stream must be parsed manually
// No high-level text extraction API
if let Some(content) = page.contents.as_ref() {
for op in content.operations.iter() {
// match on operator codes to extract text
println!("{:?}", op);
}
}
}use pdfluent::PdfDocument;
let doc = PdfDocument::open("document.pdf")?;
for i in 0..doc.page_count() {
let text = doc.page(i)?.text()?;
println!("{}", text);
}pdf-rs has no write API. PDFluent supports modifying existing documents, filling forms, adding annotations, and saving. This step has no pdf-rs equivalent.
// pdf-rs: no write API available
// Cannot modify documents, fill forms, or save changesuse pdfluent::PdfDocument;
let mut doc = PdfDocument::open("application.pdf")?;
// Fill AcroForm
let mut form = doc.acroform()?;
form.set_field("applicant_name", "Jane Smith")?;
form.set_field("date", "2024-04-14")?;
// Validate PDF/A before saving
let report = doc.validate_pdfa(pdfluent::PdfaLevel::A1b)?;
println!("Valid: {}", report.is_valid());
doc.save("application_filled.pdf")?;