Verify

Check a file, bytes or a batch against PDF/A-1b or PDF/A-2b, and read the issues it reports.

doc.Verify runs a profile (PDFA1B or PDFA2B) and returns a Result with a Valid flag and every issue found, not just the first.

verify.go
v, _ := doc.Verify(gopdfrab.PDFA1B)

if v.Valid {
	fmt.Println("Document is PDF/A-1b compliant")
} else {
	fmt.Println("Issues:")
	for i, issue := range v.Issues {
		fmt.Printf("#%v: %v\n", i+1, issue)
	}
}

Skip the open step with a path, or verify bytes that never touched disk:

verify.go
// 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)

// VerifyBytes is Verify for an in-memory PDF
result, err := gopdfrab.VerifyBytes(data, gopdfrab.PDFA1B)

VerifyAll checks a batch concurrently. Verification holds no shared state, so it scales across cores.

verify_all.go
results, err := gopdfrab.VerifyAll(paths, gopdfrab.PDFA1B)
if err != nil {
	log.Fatal(err)
}
for _, r := range results {
	if r.Err != nil {
		log.Println(r.Path, r.Err)
		continue
	}
	fmt.Println(r.Path, r.Result.Valid)
}

Reading issues

Each PDFError carries the Check that flagged it, with the ISO clause, the page and the underlying messages. Group by check before reporting: one unembedded font used on 200 pages is 200 issues but one problem.

diagnostics.go
for _, issue := range v.Issues {
	c := issue.Check()
	fmt.Println(c.Clause(), c.Subclause(), c.Name(), c.Description())
	fmt.Println(issue.Page(), issue.Messages())
}

fmt.Println(v.Summary())   // human-readable report, one line per Check
v.Checks()                 // distinct Checks violated, sorted by clause
v.IssuesByCheck()          // map[Check][]PDFError
v.IssuesOnPage(1)          // issues found on page 1 (0 = document-level)

Look up any failure in the PDF/A error reference.

JSON

Result, PDFError and Check marshal to a stable JSON shape. It is part of the public API and the same shape gopdfrab verify --json emits.

json.go
// Result, PDFError and Check marshal to a stable JSON shape,
// for CLI, service, or CI integration.
b, err := json.Marshal(v)

// {"type":"A-1b","valid":false,"issueCount":2,"issues":[
//   {"check":{"name":"...","clause":"6.1.3",...},
//    "page":0,"documentLevel":true,"messages":["..."],"text":"..."}]}