PDF/A in Go
Go has good libraries for creating and editing PDFs. Checking conformance is a different, harder problem.
Three different jobs
- Generating You control every object you write. The hard part is layout.
- Manipulating Splitting, merging or stamping needs a parser, but only for the objects it touches.
- Conformance Has to understand everything in an arbitrary file, and interpret it the way the standard does.
Why conformance is hard
A validator sees files from old scanners, truncated uploads, obsolete ciphers and attackers. It has to open them anyway, since "this file is broken" is the answer you need, without falling for a decompression bomb.
The standard is also ambiguous in places. gopdfrab's default profile follows veraPDF's reading, and a stricter legacy profile follows the letter of the spec.
Verify
// Verify opens, verifies, and closes a file in one call
result, err := gopdfrab.Verify(path, gopdfrab.PDFA1B)
if err != nil {
log.Fatal(err)
}
fmt.Println(result.Valid)Each issue carries its clause, check, page and message. See reading issues and the error reference.
Convert
cr, err := gopdfrab.Convert(path, gopdfrab.PDFA1B)
if err != nil {
log.Fatal(err)
}
defer cr.Close() // releases the output (a large one spills to a temp file)
if err := cr.Save("out.pdf"); err != nil {
log.Fatal(err)
}
fmt.Println(cr.Iterations) // how many verify/fixup passes it took
fmt.Println(cr.Result.Valid) // true if the output is fully PDF/A conformantSome documents can't conform without looking different. gopdfrab reports what it couldn't fix, and CheckFidelity shows what changed.
Why in-process helps
Validation runs in your request with typed errors, no subprocess output to parse and nothing to warm up. The same code compiles to WebAssembly, which is how the converter runs in your browser.
FAQ
Can I validate PDF/A from Go without shelling out to veraPDF?
Yes. gopdfrab is a Go library: import it, call Verify, read the issues. No subprocess and no CGo, so it cross-compiles anywhere Go does, including WebAssembly.
Does the Go standard library support PDF?
No. PDF support in Go comes from third-party libraries with quite different goals.
How do I convert a PDF to PDF/A in Go?
Call gopdfrab.Convert with the target profile. Anything it cannot fix is reported as a residual issue instead of being passed as valid.