Skip to content
Apply PDF/A-2 Standard

Apply PDF/A-2 Standard

Applying PDF/A-2 rewrites a document to ISO 19005-2 as it is written out, raising the PDF version to at least 1.7. It is the least destructive of the archival conversions, because part 2 permits transparency, optional content and JPEG 2000, so the applier does not have to remove anything to make the file conform visually.

Three profiles, one per conformance level:

ProfileAdds
pdfa.NewProfile2BNothing beyond the base rules. The usual choice.
pdfa.NewProfile2UText has to map to Unicode through a ToUnicode CMap.
pdfa.NewProfile2AEverything in 2U, plus a tagged logical structure.

Applying a profile does not add what its level requires. NewProfile2U will not synthesize ToUnicode CMaps for fonts that lack them, and NewProfile2A sets MarkInfo Marked to true and inserts an empty StructTreeRoot without tagging any content. Use 2B when converting an existing file, and reach for the higher levels only when the input already satisfies them.

Doing it

pdfWriter, err := reader.ToWriter(nil)
if err != nil {
    return err
}

pdfWriter.ApplyStandard(pdfa.NewProfile2B(nil))

return pdfWriter.WriteToFile(outputPath)

ApplyStandard registers the profile; the rewrite happens during Write. Passing nil gives DefaultProfile2Options, which uses time.Now as the clock and a tab as the XMP indent. CMYKDefaultColorSpace picks CMYK instead of RGB as the target when the document mixes device color spaces.

Beyond the shared steps, the part 2 applier removes the catalog’s Requirements and NeedsRendering entries, drops AlternatePresentations from the name dictionary, strips the AS usage arrays from optional content configurations, removes XFA from the AcroForm dictionary, and reduces the catalog’s Perms dictionary to its DocMDP and UR3 entries.

Limitations

Attachments have to be PDF/A themselves. The part 2 embedded file rule requires the embedded stream’s MIME type to be application/pdf, and the applier does not convert or remove attachments that are not. A document carrying an XML or spreadsheet attachment will not validate as PDF/A-2 no matter how it is written; that is what PDF/A-3 is for.

Fonts referenced but not embedded are replaced with a font found on the machine running the conversion, falling back to Times New Roman, Arial and DejaVu Sans, and Write fails with no matching font found in the system if none is installed. Substitutes are not metrically matched.

Interactive behavior does not survive. Every annotation gets its Print flag set and its Invisible, Hidden, NoView and ToggleNoView flags cleared, whether or not it was in violation. Widget annotations and field dictionaries lose their A and AA entries, so fields with JavaScript or other actions attached stop responding, and the AcroForm dictionary loses its XFA entry, which leaves an XFA-based dynamic form with only its AcroForm fallback.

Applying the profile does not guarantee the result validates. Check the output with validation, and with veraPDF before claiming conformance.

Run the example

pdfa2_apply_standard.go reads a file, converts it with NewProfile2B and writes the result. The only PDF/A-specific line is the ApplyStandard call in main.

git clone https://github.com/unidoc/unipdf-examples.git
cd unipdf-examples/pdfa
go run pdfa2_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.

View the full source
Processing time: 24.71 ms

Sample output

Document properties of the converted file showing the PDF/A-2 conformance claim

Last updated on