Many teams accumulate a mix of old tools: PDFBox for reading, iText for writing, custom scripts for forms, and shell wrappers around Ghostscript. Consolidate to one Rust crate.
cargo add pdfluentBefore replacing anything, list every library and tool touching PDFs in your system. Common legacy stacks include PDFBox for reading, iText for writing, a separate form library, and Ghostscript invoked via Runtime.exec() or shell scripts. Each one has its own dependency, license, and failure mode.
# Typical legacy PDF stack
# pom.xml: iText 5 (AGPL), PDFBox 2.0 (Apache)
# scripts/fill_form.sh: calls pdftk or ghostscript
# lib/pdf_util.py: Python wrapper around pdfminer
# DockerFile: installs ghostscript, pdftk, java, python
#
# Result: 4 runtimes, 3 licenses, 500+ MB image# PDFluent replaces all of the above
# Cargo.toml: pdfluent = "0.9" (MIT/commercial)
#
# One crate for: reading, writing, text extraction,
# form filling, XFA, annotations, and metadata.
# Dockerfile: copies a single static binary.Start with the lowest-risk part of the stack: reading documents and extracting text. This is typically handled by PDFBox or pdfminer and is safe to swap without changing any downstream logic. Verify output parity before moving to the next operation.
// PDFBox text extraction
PDDocument document = PDDocument.load(new File("report.pdf"));
PDFTextStripper stripper = new PDFTextStripper();
stripper.setStartPage(1);
stripper.setEndPage(document.getNumberOfPages());
String text = stripper.getText(document);
document.close();use pdfluent::Document;
let doc = Document::open("report.pdf")?;
let pages = doc.page_count();
let mut all_text = String::new();
for i in 0..pages {
all_text.push_str(&doc.page(i)?.extract_text()?);
}Legacy stacks often use a different library for writing than for reading. Replace iText or pdftk form-filling with PDFluent's acroform API. Replace Ghostscript shell invocations with PDFluent's document manipulation methods. Each replacement removes a runtime dependency from your Docker image.
// iText 5 form filling (AGPL)
PdfReader reader = new PdfReader("template.pdf");
PdfStamper stamper = new PdfStamper(
reader,
new FileOutputStream("filled.pdf")
);
AcroFields form = stamper.getAcroFields();
form.setField("company_name", "Acme Corp");
form.setField("invoice_date", "2024-04-14");
stamper.setFormFlattening(true);
stamper.close();
reader.close();let mut doc = Document::open("template.pdf")?;
let mut form = doc.acroform()?;
form.set_field("company_name", "Acme Corp")?;
form.set_field("invoice_date", "2024-04-14")?;
form.flatten()?;
doc.save("filled.pdf")?;