How-to guides/PDF/A & Archiving

Convert a PDF to PDF/A-1b, PDF/A-2b, or PDF/A-3b in Rust

Convert a standard PDF into a PDF/A archiving format. PDFluent embeds fonts, adds XMP metadata, and fixes common compliance issues automatically.

rust
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(())
}
Install:cargo add pdfluentDownload SDK →

Step by step

1

Open the source PDF

Open the document you want to convert. PDFluent will modify it in place before you save it.

rust
use pdfluent::PdfDocument;

let mut doc = PdfDocument::open("report.pdf")?;
2

Set conversion options

Choose the target PDF/A level and configure automatic fixes. embed_missing_fonts will substitute missing fonts with embedded versions where possible.

rust
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-1
3

Run the conversion

convert_to_pdf_a() applies all automatic fixes and returns a ConversionReport listing what was fixed and what could not be fixed automatically.

rust
let report = doc.convert_to_pdf_a(&opts)?;

println!("Fixed: {}", report.fixes.len());
for fix in &report.fixes {
    println!("  + {}", fix.description);
}
4

Check for unresolved issues

Some problems cannot be fixed automatically. Check report.unresolved before saving to decide whether to proceed.

rust
if !report.unresolved.is_empty() {
    eprintln!("Unresolved issues:");
    for issue in &report.unresolved {
        eprintln!("  ! {}", issue.message);
    }
}
5

Save the converted document

Save to a new path to keep the original intact.

rust
doc.save("report_pdfa2b.pdf")?;

Notes and tips

  • PDF/A-1b does not allow transparency. If your PDF uses transparency effects, either use PDF/A-2b or flatten the transparency first.
  • Fonts that cannot be embedded due to licensing restrictions will appear in report.unresolved. You must replace them manually.
  • JavaScript actions, launch actions, and embedded movies are removed during conversion because they are not allowed in PDF/A.
  • After conversion, run validate_pdf_a() to confirm the output is fully conformant before archiving.

Why PDFluent for this

Pure Rust

No JVM, no runtime, no DLL dependencies. Ships as a single native binary or WASM module.

Memory safe

Rust's ownership model prevents buffer overflows and use-after-free. No segfaults in PDF parsing.

Runs anywhere

Same code runs server-side, in Docker, on AWS Lambda, on Cloudflare Workers, or in the browser via WASM.

Frequently asked questions