PDF/A and PDF/UA validation
Validate PDF/A (every level from 1a to 4f) and PDF/UA-1 and -2 with clause ids, and convert to a chosen PDF/A level or to PDF/UA, with NexPDF for Java.
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
validatePdfaJson(level) takes 1a, 1b, 2a, 2b, 2u, 3a, 3b, 3u, 4, 4e or 4f
(or PDF/A-2b). null uses the level the document declares, or 2b.
ObjectMapper json = new ObjectMapper(); // Jackson, one JSON library among many
try (NexPdfDocument doc = NexPdfDocument.open(Path.of("archive.pdf"))) {
JsonNode report = json.readTree(doc.validatePdfaJson("2b"));
System.out.println(report.get("level").asText() + " "
+ (report.get("compliant").asBoolean() ? "compliant" : "not compliant"));
for (JsonNode f : report.get("failures")) {
System.out.println(f.get("clause").asText() + " " + f.get("message").asText() + " "
+ f.get("page") + " " + f.get("object"));
}
}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
validatePdfuaJson() 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.
JsonNode ua = json.readTree(doc.validatePdfuaJson());
System.out.println(ua.get("level").asText() + " " + ua.get("compliant") + " " + ua.get("failures").size());PDF/UA-1 follows the Matterhorn Protocol. PDF/UA-2 validation covers the 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.
validatePdfuaPartJson(part) validates against PDF/UA-1 (1) or PDF/UA-2 (2) whatever the
document declares, with the same report:
JsonNode ua2 = json.readTree(doc.validatePdfuaPartJson(2));Convert to a level
convertPdfaLevel(level) converts to the level you choose (null 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 NexPdfException with that list:
try (NexPdfDocument doc = NexPdfDocument.open(Path.of("report.pdf"))) {
try {
doc.convertPdfaLevel("3a");
} catch (NexPdfException e) {
System.out.println("still failing: " + e.getMessage()); // the document keeps the fixes that worked
}
doc.save(Path.of("report-pdfa3a.pdf"));
}Convert with a report
convertPdfaJson(level, flattenDpi, substituteFonts) converts like convertPdfaLevel but does not
fail when clauses remain: it reports them. level is 1a to 4f (null or "" is 2b),
flattenDpi is the resolution PDF/A-1 transparency is flattened at (0 or less is 300), and
substituteFonts 0 leaves non-embedded non-standard fonts alone.
JsonNode r = json.readTree(doc.convertPdfaJson("1b", 0, 1));
System.out.println(r.get("level").asText() + " " + r.get("compliant"));
for (JsonNode f : r.get("substitutions")) {
System.out.println(f.get("original").asText() + " -> " + f.get("substitute").asText()
+ " exact " + f.get("exact") + " widths adjusted " + f.get("widths_adjusted"));
}
for (JsonNode left : r.get("remaining")) {
System.out.println(left.get("clause").asText() + " " + left.get("message").asText());
}The report has level, compliant, fixed, substitutions (original, substitute, exact,
widths_adjusted) and remaining (clause, message, page, object).
PDF/A conversion flattens PDF/A-1 transparency into opaque image patches (text stays text), fixes device colour (a CMYK output intent, Default colour spaces), draws missing appearance streams for widgets and markup annotations, substitutes metric-compatible fonts for non-embedded fonts and removes unreachable objects. For PDF/A-4e it keeps U3D and PRC 3D streams and 3D and RichMedia annotations.
Substitute fonts
NexPdf.registerSubstituteFont(data) registers TrueType font data (with glyf outlines) for
PDF/A and PDF/UA font substitution: non-embedded fonts with the same PostScript or family name use
it. It returns the PostScript name.
String name = NexPdf.registerSubstituteFont(Files.readAllBytes(Path.of("Garamond.ttf")));Convert to PDF/UA
convertPdfuaJson(part, lang) converts to PDF/UA-1 (1) or PDF/UA-2 (2): it tags an untagged
document and embeds fonts; for part 2 it uses the PDF 2.0 namespace, structure destinations and
the annotation rules. lang (null or "" is en-US) applies when the document has no
language.
try (NexPdfDocument doc = NexPdfDocument.open(Path.of("report.pdf"))) {
JsonNode r = json.readTree(doc.convertPdfuaJson(2, "en-GB"));
System.out.println(r.get("profile").asText() + " " + r.get("compliant") + " " + r.get("remaining"));
doc.save(Path.of("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.