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 Flutter.

English

License module

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

These functions have no Dart method. Call them through dart:ffi on doc.handle, then save with doc.save().

PDF/A and PDF/X

nexpdf_convert_pdfa(doc) 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. nexpdf_convert_pdfx(doc) prepares the document for print.

import 'dart:ffi';
import 'nexpdf_ffi.dart';

// int32_t nexpdf_convert_pdfa(NexPdfDocument *doc);   int32_t nexpdf_convert_pdfx(NexPdfDocument *doc);
final convertPdfa = nexpdfLib.lookupFunction<Int32 Function(Pointer<Void>), int Function(Pointer<Void>)>('nexpdf_convert_pdfa');
final convertPdfx = nexpdfLib.lookupFunction<Int32 Function(Pointer<Void>), int Function(Pointer<Void>)>('nexpdf_convert_pdfx');

nexpdfCall(() => convertPdfa(doc.handle));
final archived = doc.save();

nexpdf_convert_pdfa writes PDF/A-2b. To convert to another level (1a to 4f) and check the result, use the Dart methods doc.convertPdfaLevel(level: ...) and doc.validatePdfa(level: ...); see PDF/A and PDF/UA validation.

PDF/UA accessibility tagging

nexpdf_auto_tag(doc, 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.

import 'dart:convert';
import 'package:ffi/ffi.dart';

// char *nexpdf_auto_tag(NexPdfDocument *doc, const char *lang, int32_t force);
final autoTag = nexpdfLib.lookupFunction<Pointer<Utf8> Function(Pointer<Void>, Pointer<Utf8>, Int32),
    Pointer<Utf8> Function(Pointer<Void>, Pointer<Utf8>, int)>('nexpdf_auto_tag');

final json = using((a) => nexpdfCall(() => takeString(autoTag(doc.handle, 'en-US'.toNativeUtf8(allocator: a), 0))));
final report = jsonDecode(json!) as Map<String, Object?>;   // force 1 re-tags an already tagged file
print('${report['headings']} ${report['paragraphs']} ${report['figures']} ${report['warnings']}');
final accessible = doc.save();

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 (nullptr uses en-US). Check the result with doc.validatePdfua(), or convert in one step to PDF/UA-1 or PDF/UA-2 with convert_pdfua_json (through sdk.invoke); see PDF/A and PDF/UA validation.

On this page