PDF/A is an archival PDF format that embeds fonts and forbids encryption and JavaScript so the pages can render the same way later. Use pdfa.ConvertFile to make an archival copy of input.pdf (“Warehouse receipt: 12 cartons”) and list the changes.
go get recursiveai.org/go/onepdfIn the unzipped folder, run go run . with Go 1.26.8.
package main import ( "context" "fmt" "log" "recursiveai.org/go/onepdf/pdfa" ) func main() { ctx := context.Background() result, err := pdfa.ConvertFile(ctx, "archive.pdf", "input.pdf", ) if err != nil { log.Fatal(err) } fmt.Println("Wrote archive.pdf") fmt.Println("Profile:", result.Profile) for _, change := range result.Changes { fmt.Println("-", change.Description) } }
Paste the code above into main.go, run go mod init example and go get recursiveai.org/go/onepdf, then go run .; or unzip the example and go run ..
If you paste the code, copy input.pdf from the zip into your project folder, or put your own PDF there named input.pdf.
The program prints:
Wrote archive.pdf Profile: PDF/A-2b - an output intent with a generated RGB profile was added - the XMP metadata was written from the information dictionary
The converter added a color profile and wrote XMP, the PDF’s embedded metadata. If conversion is refused, the diagnostic lists the reasons and ConvertFile leaves the destination untouched.
Variations
Request PDF/A-3u instead of PDF/A-2b. Replace the ConvertFile call. Part 3 permits arbitrary attachments and level U requires Unicode mappings for text:
result, err := pdfa.ConvertFile(ctx, "archive.pdf", "input.pdf", pdfa.WithPart(pdfa.Part3), pdfa.WithConformance(pdfa.ConformanceU), )
The same receipt printed Profile: PDF/A-3u and reported an additional font repair.
Related recipes
The short answer
To convert a PDF to PDF/A in Go, call pdfa.ConvertFile with the destination path first, then the source path. The default target is PDF/A-2b. Read result.Profile for the selected profile and result.Changes for the repairs. Use a separate destination path so you can review the archival copy before deciding what to do with the source.
What is the difference between PDF and PDF/A?
A regular PDF can rely on fonts it does not embed or use features such as JavaScript or encryption. PDF/A restricts those features so a saved document can be reproduced in the future. Renaming a file or editing its metadata can’t make it meet those restrictions.
How do I convert an existing PDF to PDF/A if it uses missing fonts?
The example input already embeds its font, so it needs no extra font provider. Real PDFs may name a font without embedding it. For those files, the separate substitute fonts module supplies Liberation and Noto fonts that you can give to the converter. A substitute can change the shapes of the letters; compare the resulting pages to the source if appearance matters. Font substitution can also be disabled if a changed font is unacceptable.
The converter may remove features that the target disallows. For example, the default part 2 conversion removes embedded files; if you need to retain arbitrary attachments, choose part 3. If you don’t want prohibited features removed automatically, configure the conversion to refuse them instead. When a conversion fails, keep the input and read the diagnostic before trying a different profile.
Which PDF/A format should I use?
Start with the archive’s submission requirements. When you can choose, PDF/A-2b targets reproducible appearance. PDF/A-2u also requires a Unicode mapping for text, useful when downstream tools need to interpret characters. Use part 3 where arbitrary embedded files are part of the deliverable; the variation pairs it with level U. Level U is not a request to recognize text in a scan or to add document structure. The converter does not produce PDF/A-1, PDF/A-4, or level A. If a recipient specifies one of those, changing the parameters in this example won’t meet their requirement.