Apply PDF/A-4 Standard
PDF/A-4 is ISO 19005-4, and it is the part to reach for on new work. It is built on PDF 2.0 rather than PDF 1.4 or 1.7, which changes what a conversion has to do to the content: applying it raises the document to version 2.0 and leaves transparency and modern encryption-free features alone rather than flattening them out.
No A, B or U levels
Parts 1 to 3 offer conformance levels (1a, 1b, 2b, 2u and so on). Part 4 drops
them and defines three separate profiles instead:
| Constructor | Standard name | For |
|---|---|---|
pdfa.NewProfile4(nil) | PDF/A-4 | The baseline. Start here. |
pdfa.NewProfile4F(nil) | PDF/A-4f | Documents carrying embedded files. |
pdfa.NewProfile4E(nil) | PDF/A-4e | Engineering documents, the successor to PDF/E. |
So there is no “accessible” variant to choose here. Tagging is handled separately, and
the guidance in apply PDF/A-1 about Profile1A not being
able to tag untagged content does not apply.
Doing it
pdfWriter, err := reader.ToWriter(nil)
if err != nil {
return err
}
pdfWriter.ApplyStandard(pdfa.NewProfile4(nil))
return pdfWriter.WriteToFile(outputPath)Identical in shape to the other parts: ApplyStandard only registers the profile, and
the document is rewritten inside Write, so that is where conversion errors surface.
Passing nil uses DefaultProfile4Options, which is time.Now as the clock and a tab
as the XMP indent. CMYKDefaultColorSpace is the option worth setting when the document
mixes device color spaces and you want CMYK rather than RGB as the target.
What the conversion changes
The part 4 applier is noticeably lighter than the part 1 one. It raises the version to 2.0 if the file is older, normalizes the document info object and the catalog version, checks and converts color spaces, writes output intents, updates the XMP metadata to carry the part 4 identification, and computes a hash-based file ID.
What it does not do is the disruptive work part 1 has to: there is no transparency
flattening and no SMask rewriting, because PDF 2.0 permits both. If you have been
avoiding PDF/A because part 1 mangled your artwork, this is the reason to look again.
Limitations
Embedded files are the usual reason a conversion fails validation here. Plain PDF/A-4
does not admit them; use NewProfile4F for a document with attachments.
Applying a profile does not guarantee the result validates. The applier fixes mechanical problems and cannot invent what is missing. Run validation on the output, and an independent checker such as veraPDF before making a conformance claim.
Run the example
pdfa4_apply_standard.go reads a file, converts it with NewProfile4, writes the
result and prints the elapsed time. The single ApplyStandard call in main is
everything specific to PDF/A.
git clone https://github.com/unidoc/unipdf-examples.git
cd unipdf-examples/pdfa
go run pdfa4_apply_standard.go <input.pdf> <output.pdf>If this is your first time using UniPDF, follow the getting started guide to create an API key and set up your development environment.