Skip to Content
NexPDF

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 or PDF/UA level, with NexPDF for .NET.

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

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.

using System.Text.Json.Nodes;
using Nexdevit.NexPdf;

using var doc = NexPdfDocument.Open("archive.pdf");
var report = JsonNode.Parse(doc.ValidatePdfaJson("2b"))!;
Console.WriteLine($"{report["level"]} {(report["compliant"]!.GetValue<bool>() ? "compliant" : "not compliant")}");
foreach (var f in report["failures"]!.AsArray())
    Console.WriteLine($"{f!["clause"]} {f["message"]} {f["page"]} {f["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.

var ua = JsonNode.Parse(doc.ValidatePdfuaJson())!;
Console.WriteLine($"{ua["level"]} {ua["compliant"]} {ua["failures"]!.AsArray().Count}");

PDF/UA-1 follows the Matterhorn Protocol. PDF/UA-2 validation covers 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:

var ua2 = JsonNode.Parse(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:

using var doc = NexPdfDocument.Open("report.pdf");
try
{
    doc.ConvertPdfaLevel("3a");
}
catch (NexPdfException e)
{
    Console.WriteLine($"still failing: {e.Message}");   // the document keeps the fixes that worked
}
doc.Save("report-pdfa3a.pdf");

Convert with a report

ConvertPdfaJson(level, flattenDpi, substituteFonts) converts like ConvertPdfaLevel, but does not throw when clauses remain: it reports them.

var r = JsonNode.Parse(doc.ConvertPdfaJson("1b", 300, 1))!;
Console.WriteLine($"{r["level"]} {r["compliant"]}");
foreach (var s in r["substitutions"]!.AsArray())
    Console.WriteLine($"{s!["original"]} -> {s["substitute"]} exact: {s["exact"]}");
foreach (var f in r["remaining"]!.AsArray())
    Console.WriteLine($"{f!["clause"]} {f["message"]} {f["page"]} {f["object"]}");
ArgumentMeaning
level1a to 4f; null or "" is 2b
flattenDpiResolution PDF/A-1 transparency is flattened at; 0 or less is 300
substituteFonts0 leaves non-embedded, non-standard fonts alone

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

Conversion flattens PDF/A-1 transparency into 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 removes unreachable objects. For PDF/A-4e it handles U3D and PRC 3D streams and 3D and RichMedia annotations.

To substitute a font of your own, register TrueType (glyf) font data. Non-embedded fonts with the same PostScript or family name then use it, in PDF/A and PDF/UA conversion:

string? name = NexPdfSdk.RegisterSubstituteFont(File.ReadAllBytes("Corporate.ttf"));   // PostScript name, or null

Convert to PDF/UA

ConvertPdfuaJson(part, lang) converts to PDF/UA-1 or PDF/UA-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.

var ua = JsonNode.Parse(doc.ConvertPdfuaJson(2, "pt-PT"))!;
Console.WriteLine($"{ua["profile"]} {ua["compliant"]} {ua["remaining"]!.AsArray().Count}");
doc.Save("accessible-ua2.pdf");

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

OCR text layers use glyph-less TrueType fonts, so run OCR before converting a document that must be PDF/A.

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

On this page