Skip to Content
NexPDF

PDF/A and PDF/UA

Convert documents to PDF/A for archiving or PDF/X for print, and tag them for PDF/UA accessibility, with NexPDF for Rust.

English

License module

PDF/A, PDF/X and PDF/UA need the standards module (Enterprise tier).

PDF/A for archiving

convert_pdfa() converts the document to PDF/A (ISO 19005): it writes the XMP metadata with the PDF/A identification, adds an sRGB output intent with an embedded ICC profile and a file identifier, and embeds metric-compatible Liberation fonts in place of non-embedded standard fonts.

use nexpdf_sdk::Document;

fn main() -> nexpdf_sdk::Result<()> {
    let mut doc = Document::open("invoice.pdf")?;
    doc.convert_pdfa()?;
    doc.save("invoice-pdfa.pdf")
}

convert_pdfa() writes PDF/A-2b. To convert to another level (1a to 4f) and check the result, use convert_pdfa_level(level) and validate_pdfa_json(level); see PDF/A and PDF/UA validation.

In a build without bundled fonts, register the Liberation fonts first with nexpdf_sdk::register_standard_font(data); nexpdf_sdk::has_bundled_fonts() tells which build you have.

PDF/X for print

doc.convert_pdfx()?;
doc.save("print-ready.pdf")?;

PDF/UA accessibility tagging

auto_tag(lang, force) builds a logical structure tree from the page content of an untagged document: text becomes headings (H1, H2) and paragraphs in reading order, images become Figure elements with placeholder alternative text, annotations become Link, Form or Annot elements, and vector graphics become artifacts. It also sets the language, the title, /MarkInfo, the tab order and the PDF/UA identification. It returns a JSON report as a String.

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let mut doc = nexpdf_sdk::Document::open("report.pdf")?;
    let report: serde_json::Value = serde_json::from_str(&doc.auto_tag("en-US", 0)?)?;   // force 1 re-tags a tagged file
    println!("{} {} {} {}", report["headings"], report["paragraphs"], report["figures"], report["warnings"]);
    doc.save("accessible.pdf")?;
    Ok(())
}

The report counts pages, headings, paragraphs, figures, annotations and artifacts, says whether the file was already_tagged, and lists warnings that need a person, such as figures that need real alternative text.

lang is a BCP 47 tag such as pt-PT or en-US (None uses en-US). Check the result with validate_pdfua_json(). convert_pdfua_json(part, lang) tags, fixes and reports in one call for PDF/UA-1 or PDF/UA-2; see PDF/A and PDF/UA validation.

On this page