Convert a standard PDF into a PDF/A archiving format. PDFluent embeds fonts, adds XMP metadata, and fixes common compliance issues automatically.
use pdfluent::{PdfDocument, PdfALevel, ConvertOptions};
fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut doc = PdfDocument::open("report.pdf")?;
let opts = ConvertOptions::default()
.level(PdfALevel::PdfA2b)
.embed_missing_fonts(true);
let report = doc.convert_to_pdf_a(&opts)?;
doc.save("report_pdfa2b.pdf")?;
println!("Converted. Remaining issues: {}", report.unresolved.len());
Ok(())
}Open the document you want to convert. PDFluent will modify it in place before you save it.
use pdfluent::PdfDocument;
let mut doc = PdfDocument::open("report.pdf")?;Choose the target PDF/A level and configure automatic fixes. embed_missing_fonts will substitute missing fonts with embedded versions where possible.
use pdfluent::{PdfALevel, ConvertOptions};
let opts = ConvertOptions::default()
.level(PdfALevel::PdfA2b)
.embed_missing_fonts(true)
.add_xmp_metadata(true)
.remove_javascript(true)
.remove_transparency(false); // only needed for PDF/A-1convert_to_pdf_a() applies all automatic fixes and returns a ConversionReport listing what was fixed and what could not be fixed automatically.
let report = doc.convert_to_pdf_a(&opts)?;
println!("Fixed: {}", report.fixes.len());
for fix in &report.fixes {
println!(" + {}", fix.description);
}Some problems cannot be fixed automatically. Check report.unresolved before saving to decide whether to proceed.
if !report.unresolved.is_empty() {
eprintln!("Unresolved issues:");
for issue in &report.unresolved {
eprintln!(" ! {}", issue.message);
}
}Save to a new path to keep the original intact.
doc.save("report_pdfa2b.pdf")?;No JVM, no runtime, no DLL dependencies. Ships as a single native binary or WASM module.
Rust's ownership model prevents buffer overflows and use-after-free. No segfaults in PDF parsing.
Same code runs server-side, in Docker, on AWS Lambda, on Cloudflare Workers, or in the browser via WASM.