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, PdfALevel};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let doc = PdfDocument::open("archive_candidate.pdf")?;
    let report = doc.validate_pdf_a(PdfALevel::PdfA2b)?;

    if report.is_conformant {
        println!("Conforms to PDF/A-2b");
    } else {
        for v in &report.violations {
            println!("[{}] {}", v.rule_id, v.message);
        }
    }
    Ok(())
}
Install:cargo add pdfluentDownload SDK →

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::PdfALevel;

// Options: PdfALevel::PdfA1b, PdfA2b, PdfA3b
let level = PdfALevel::PdfA2b;
3

Run the validator

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

rust
let report = doc.validate_pdf_a(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!("Conformant: {}", report.is_conformant);
println!("Violations: {}", report.violations.len());

for v in &report.violations {
    println!(
        "Rule {} on page {:?}: {}",
        v.rule_id, 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_conformant {
    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