Skip to Content
NexPDF

PDF/A and PDF/UA validation

Validate PDF/A (every level from 1a to 4f) and PDF/UA with clause ids, and convert to a chosen PDF/A level, with NexPDF for Rust.

English

License module

Validation and conversion need the standards module (Enterprise tier).

NexPDF checks documents against the machine-checkable rules of PDF/A (ISO 19005-1 to -4) and PDF/UA (ISO 14289). Each failure names the clause of the standard that requires it, with the same numbers the veraPDF rule sets use.

Validate PDF/A

validate_pdfa_json(level) takes 1a, 1b, 2a, 2b, 2u, 3a, 3b, 3u, 4, 4e or 4f (or PDF/A-2b). None uses the level the document declares, or 2b.

use nexpdf_sdk::Document;

fn main() -> nexpdf_sdk::Result<()> {
    let doc = Document::open("archive.pdf")?;
    let report = doc.validate_pdfa_json_value("2b")?;       // `serde` feature; or validate_pdfa_json
    let compliant = report["compliant"].as_bool() == Some(true);
    println!("{} {}", report["level"], if compliant { "compliant" } else { "not compliant" });
    for f in report["failures"].as_array().into_iter().flatten() {
        println!("{} {} {} {}", f["clause"], f["message"], f["page"], f["object"]);
    }
    Ok(())
}

Each failure has clause (such as 6.2.11.4.1), message, page (1-based, or null) and object (such as 12 0 R, or null).

The rules cover file structure, metadata (XMP, pdfaid, extension schemas), fonts (embedding, glyphs, widths, encodings), colour (output intents, ICC profiles), graphics and transparency, interactive features (annotations, actions, forms, embedded files) and, for level A, the tagged structure.

Validate PDF/UA

validate_pdfua_json() validates against the PDF/UA part the document declares, PDF/UA-1 by default. The report has the same shape, with level PDF/UA-1 or PDF/UA-2.

let ua = doc.validate_pdfua_json_value()?;
let failures = ua["failures"].as_array().map_or(0, |f| f.len());
println!("{} {} {failures}", ua["level"], ua["compliant"]);

PDF/UA-1 follows the Matterhorn Protocol. PDF/UA-2 follows ISO 14289-2: PDF 2.0 namespaces (/NS, /RoleMapNS, the root /RoleMap, MathML), structure, annotation, form, destination and text-string rules, and the ISO/TS 32005 parent/child rules.

validate_pdfua_part_json(part) validates against PDF/UA-1 (1) or PDF/UA-2 (2) whatever the document declares. The report has the same shape.

let ua2 = doc.validate_pdfua_part_json_value(2)?;          // `serde`; or validate_pdfua_part_json
println!("{} {}", ua2["level"], ua2["compliant"]);

Convert to a level

convert_pdfa_level(level) converts to the level you choose (None is 2b). Level A tags the document first. When the result validates against the level it returns Ok(1). When some clauses still fail, the fixes that could be made are kept and the engine reports the clauses that are left as the error, so the call returns Err(Error::Engine(..)) with that list:

let mut doc = Document::open("report.pdf")?;
if let Err(e) = doc.convert_pdfa_level("3a") {
    println!("still failing: {e}");        // the document keeps the fixes that worked
}
doc.save("report-pdfa3a.pdf")?;

Convert with a report

convert_pdfa_json(level, flatten_dpi, substitute_fonts) converts like convert_pdfa_level but does not fail when clauses remain: it reports them.

let mut doc = Document::open("report.pdf")?;
let r = doc.convert_pdfa_json_value("1b", 300.0, 1)?;     // `serde`; or convert_pdfa_json
println!("{} {}", r["level"], r["compliant"]);
for c in r["remaining"].as_array().into_iter().flatten() {
    println!("{} {}", c["clause"], c["message"]);
}
doc.save("report-pdfa1b.pdf")?;
ParameterMeaning
level1a ... 4f; None or "" is 2b
flatten_dpiResolution PDF/A-1 transparency is flattened at; 0.0 or less is 300
substitute_fonts0 leaves non-embedded non-standard fonts alone; 1 substitutes them

The report has level, compliant, fixed, substitutions (each with original, substitute, exact and widths_adjusted) and remaining (each with clause, message, page and object).

The conversion flattens PDF/A-1 transparency into opaque image patches (text stays text), fixes device colour (a CMYK output intent or Default colour spaces), draws missing appearance streams for widgets and markup annotations, substitutes metric-compatible fonts for non-embedded fonts and prunes unreachable objects. For PDF/A-4e it handles U3D/PRC 3D streams and 3D and RichMedia annotations.

To substitute a font of your own, register its TrueType (glyf) data first. Non-embedded fonts with the same PostScript or family name then use it. It returns the PostScript name:

let name = nexpdf_sdk::register_substitute_font(&std::fs::read("Frutiger.ttf")?)?;

OCR text layers use glyph-less fonts: convert to PDF/A after OCR.

Convert to PDF/UA

convert_pdfua_json(part, lang) converts to PDF/UA-1 (1) or PDF/UA-2 (2): it tags an untagged document and embeds fonts, and for part 2 uses the PDF 2.0 namespace, structure destinations and the annotation rules. lang (None or "" is en-US) applies when the document has no language.

let mut doc = Document::open("report.pdf")?;
let r = doc.convert_pdfua_json_value(2, "en-GB")?;         // `serde`; or convert_pdfua_json
println!("{} {} {}", r["profile"], r["compliant"], r["remaining"]);
doc.save("report-ua2.pdf")?;

The report has profile, compliant, fixed, warnings, substitutions and remaining.

See PDF/A, PDF/X and PDF/UA for PDF/X and accessibility tagging.

On this page