Skip to Content
NexPDF

PDF/A and PDF/UA validation

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

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). std::nullopt uses the level the document declares, or 2b.

#include <nexpdf.hpp>
#include <nlohmann/json.hpp>   // an example; use your JSON library

namespace nexpdf = nexdevit::nexpdf;

auto doc = nexpdf::Document::open("archive.pdf");
auto report = nlohmann::json::parse(doc.validate_pdfa_json("2b"));
std::cout << report["level"] << (report["compliant"].get<bool>() ? " compliant" : " not compliant") << "\n";
for (const auto& f : report["failures"])
    std::cout << f["clause"] << " " << f["message"] << " " << f["page"] << " " << f["object"] << "\n";

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.

auto ua = nlohmann::json::parse(doc.validate_pdfua_json());
std::cout << ua["level"] << " " << ua["compliant"] << " " << ua["failures"].size() << "\n";

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

validate_pdfua_part_json(part) validates against PDF/UA-1 (1) or PDF/UA-2 (2) whatever the document declares, with the same report:

auto ua2 = nlohmann::json::parse(doc.validate_pdfua_part_json(2));

Convert to a level

convert_pdfa_level(level) converts to the level you choose (std::nullopt is 2b). Level A tags the document first. When the result validates against the level it returns 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 throws nexdevit::nexpdf::Error with that list:

auto doc = nexpdf::Document::open("report.pdf");
try {
    doc.convert_pdfa_level("3a");
} catch (const nexpdf::Error& e) {
    std::cerr << "still failing: " << e.what() << "\n";   // the document keeps the fixes that worked
}
doc.save("report-pdfa3a.pdf");

From C, nexpdf_convert_pdfa_level returns 0 in that case and nexpdf_last_error() holds the list.

Convert with a report

convert_pdfa_json(level, flatten_dpi, substitute_fonts) converts like convert_pdfa_level but does not throw when clauses remain: it reports them. flatten_dpi is the resolution PDF/A-1 transparency is flattened at (0 = 300); substitute_fonts 0 leaves non-embedded fonts that are not standard fonts alone.

nexpdf::register_substitute_font(read_file("Arimo-Regular.ttf"));   // returns the PostScript name

auto conv = nlohmann::json::parse(doc.convert_pdfa_json("2b", 300, 1));
std::cout << conv["compliant"] << " " << conv["remaining"].size() << "\n";
for (const auto& s : conv["substitutions"])
    std::cout << s["original"] << " -> " << s["substitute"] << "\n";

The result has level, compliant, fixed, substitutions (original, substitute, exact, widths_adjusted) and remaining (clause, message, page, object). The conversion flattens PDF/A-1 transparency to opaque image patches (text stays text), fixes device colour (CMYK output intent, 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 also handles U3D/PRC 3D streams and 3D and RichMedia annotations.

nexpdf::register_substitute_font(data) registers TrueType (glyf) font data for PDF/A and PDF/UA substitution: non-embedded fonts with the same PostScript or family name use it.

convert_pdfua_json(part, lang) converts to PDF/UA-1 or PDF/UA-2: it tags an untagged document, embeds fonts and, for part 2, uses the PDF 2.0 namespace, structure destinations and the annotation rules. lang (std::nullopt = en-US) applies when the document has none. It returns {"profile","compliant","fixed","warnings","substitutions","remaining"}.

auto ua = nlohmann::json::parse(doc.convert_pdfua_json(2, "en-US"));

OCR text layers use glyph-less fonts, so convert to PDF/A after OCR, not before.

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

On this page