How-to guides/PDF/A & Archiving

Validate PDF/A compliance in Rust

Check whether a PDF meets PDF/A-1b, PDF/A-2b, or PDF/A-3b archiving requirements. Get a structured list of violations with page and object references.

rust
use pdfluent::{PdfDocument, PdfAProfile};

fn main() -> pdfluent::Result<()> {
    let doc = PdfDocument::open("invoice.pdf")?;
    let report = doc.validate_pdfa(PdfAProfile::A2b)?;
    if report.is_compliant() {
        println!("PDF/A-2B compliant");
    }
    Ok(())
}

Step by step

1

Open the PDF

Open the document you want to validate. The validator reads the entire structure, so larger files take slightly longer.

rust
use pdfluent::PdfDocument;

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

Choose the conformance level

PDFluent supports PDF/A-1b, PDF/A-2b, and PDF/A-3b. Choose the level your archiving policy requires.

rust
use pdfluent::PdfAProfile;

// Options: PdfAProfile::A1b, A2b, A3b
let level = PdfAProfile::A2b;
3

Run the validator

Call validate_pdf_a() with the level. It returns a ValidationReport.

rust
let report = doc.validate_pdfa(level)?;
4

Check the result

report.is_conformant is true when no violations were found. report.violations is a Vec<Violation> with details for each issue.

rust
println!("Compliant: {}", report.is_compliant());
println!("Violations: {}", report.violations.len());

for v in &report.violations {
    println!(
        "Rule {} on page {:?}: {}",
        v.rule, v.page, v.message,
    );
}
5

Exit with a non-zero code on failure

In a CI pipeline, return exit code 1 when violations are found so the build fails automatically.

rust
if !report.is_compliant() {
    eprintln!("{} violation(s) found", report.violations.len());
    std::process::exit(1);
}

Notes and tips

  • PDF/A-1b requires all fonts to be embedded. A missing font embedding is the most common violation.
  • PDF/A-2b adds support for JPEG 2000 compression and Optional Content (layers).
  • PDF/A-3b allows embedding of arbitrary file attachments, which PDF/A-1b and PDF/A-2b prohibit.
  • The validator checks structure and metadata but does not re-render pages. It cannot catch rendering errors.

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