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

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

doc.validatePdfa(level: ...) takes 1a, 1b, 2a, 2b, 2u, 3a, 3b, 3u, 4, 4e or 4f (or PDF/A-2b). Without level it uses the level the document declares, or 2b.

import 'dart:io';
import 'package:nexpdf_flutter/nexpdf_flutter.dart';

final doc = sdk.open(await File(archivePath).readAsBytes());
final report = doc.validatePdfa(level: '2b');
print('${report['level']} ${report['compliant'] == true ? 'compliant' : 'not compliant'}');
for (final f in (report['failures'] as List).cast<Map<String, Object?>>()) {
  print('${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

doc.validatePdfua() 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.

final ua = doc.validatePdfua();
print('${ua['level']} ${ua['compliant']} ${(ua['failures'] as List).length}');

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.

The functions below have no typed Dart method yet. Reach them through sdk.invoke, which works on invoke handles (integers) rather than NexPdfDocument objects: open the file with sdk.invoke('open_bytes', [bytes]), save it with sdk.invoke('save_bytes', [h]) (base64) and free it with sdk.invoke('close', [h]).

To validate against one part whatever the document declares, call validate_pdfua_part_json with 1 or 2. It returns the same report.

import 'dart:convert';

final h = sdk.invoke('open_bytes', [await File(reportPath).readAsBytes()]) as int;
final ua2 = jsonDecode(sdk.invoke('validate_pdfua_part_json', [h, 2]) as String) as Map<String, Object?>;
print('${ua2['level']} ${ua2['compliant']}');

Convert to PDF/UA

convert_pdfua_json (through invoke, with part and lang) converts to PDF/UA-1 (1) or PDF/UA-2 (2): it tags an untagged document, embeds fonts and, for part 2, uses the PDF 2.0 namespace, structure destinations and the PDF/UA-2 annotation rules. lang (null is en-US) applies when the document has no language. The report has profile, compliant, fixed, warnings, substitutions and remaining.

final r = jsonDecode(sdk.invoke('convert_pdfua_json', [h, 2, 'en-GB']) as String) as Map<String, Object?>;
print('${r['profile']} ${r['compliant']} ${r['fixed']} ${r['warnings']}');
await File(pdfua2Path).writeAsBytes(base64Decode(sdk.invoke('save_bytes', [h]) as String));
sdk.invoke('close', [h]);

Convert to a level

doc.convertPdfaLevel(level: ...) converts to the level you choose (2b without level). Level A tags the document first. It returns true when the result validates against the level. When some clauses still fail it returns false: the fixes that could be made are kept, and sdk.lastError() lists the clauses that are left.

final doc = sdk.open(await File(reportPath).readAsBytes());
if (!doc.convertPdfaLevel(level: '3a')) {
  print('still failing: ${sdk.lastError()}');   // the document keeps the fixes that worked
}
await File(pdfaPath).writeAsBytes(doc.save());

Conversion with a report

convert_pdfa_json (through invoke, with level, flatten_dpi and substitute_fonts) converts like convertPdfaLevel but does not fail when clauses remain: it reports them.

ArgumentMeaning
level1a to 4f; null is 2b
flatten_dpiResolution at which PDF/A-1 transparency is flattened; 0 or less is 300
substitute_fonts1 replaces non-embedded fonts with metric-compatible ones; 0 leaves non-embedded non-standard fonts alone
final h = sdk.invoke('open_bytes', [await File(reportPath).readAsBytes()]) as int;
final r = jsonDecode(sdk.invoke('convert_pdfa_json', [h, '1b', 300, 1]) as String) as Map<String, Object?>;
print('${r['level']} ${r['compliant']} ${r['fixed']}');
for (final s in r['substitutions'] as List) {
  print('${s['original']} -> ${s['substitute']} ${s['exact']} ${s['widths_adjusted']}');
}
for (final f in r['remaining'] as List) {
  print('${f['clause']} ${f['message']} ${f['page']} ${f['object']}');
}
await File(pdfaPath).writeAsBytes(base64Decode(sdk.invoke('save_bytes', [h]) as String));
sdk.invoke('close', [h]);

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

To use your own font for substitution, register its TrueType data (with glyf outlines) first. Non-embedded fonts with the same PostScript or family name then use it:

final name = sdk.invoke('register_substitute_font', [await File(frutigerPath).readAsBytes()]) as String;
print('registered $name');

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

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

On this page