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

English

License module

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

PDF/A for archiving

ConvertPDFA() 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.

doc, err := nexpdf.Open("invoice.pdf")
if err != nil {
	log.Fatal(err)
}
defer doc.Close()

if _, err := doc.ConvertPDFA(); err != nil {
	log.Fatal(err)
}
doc.Save("invoice-pdfa.pdf", false)

ConvertPDFA() writes PDF/A-2b. To convert to another level (1a to 4f) and check the result, use ConvertPDFALevel(level) and ValidatePDFAJSON(level); see PDF/A and PDF/UA validation.

In a build without bundled fonts, register the Liberation fonts first with nexpdf.RegisterStandardFont(data); nexpdf.HasBundledFonts() tells which build you have.

PDF/X for print

doc.ConvertPDFX()
doc.Save("print-ready.pdf", false)

PDF/UA accessibility tagging

AutoTag(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.

type TagReport struct {
	AlreadyTagged bool     `json:"already_tagged"`
	Pages         int      `json:"pages"`
	Headings      int      `json:"headings"`
	Paragraphs    int      `json:"paragraphs"`
	Figures       int      `json:"figures"`
	Annotations   int      `json:"annotations"`
	Artifacts     int      `json:"artifacts"`
	Warnings      []string `json:"warnings"`
}

s, err := doc.AutoTag("en-US", 0) // force 1 re-tags an already tagged file
if err != nil {
	log.Fatal(err)
}
var report TagReport
json.Unmarshal([]byte(s), &report)
fmt.Println(report.Headings, report.Paragraphs, report.Figures, report.Warnings)
doc.Save("accessible.pdf", false)

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 ("" uses en-US). Check the result with ValidatePdfuaJSON(); see PDF/A and PDF/UA validation.

On this page