CLI

The library as a single binary. Verify files and directories, convert, and gate CI on the exit code.

terminal
go install github.com/voidrab/gopdfrab/cmd/gopdfrab@latest
terminal
$ gopdfrab verify --profile pdfa2b invoice.pdfFAIL  issues=5  invoice.pdf  6.1.3/1       trailer does not contain the required ID keyword  6.2.4.3       device colour (rgb) used without matching OutputIntent  6.2.11.4.1/1  font Helvetica is not embedded  6.2.11.4.1/1  font Helvetica-Bold is not embedded  6.6.2.1/1     document catalog lacks a Metadata entrysummary: pass=0 fail=1 error=0 files=1$ gopdfrab convert --profile pdfa2b invoice.pdf invoice-a2b.pdfoutput: invoice-a2b.pdfiterations: 3result: conformant$ gopdfrab verify --profile pdfa2b invoice-a2b.pdfPASS  invoice-a2b.pdfsummary: pass=1 fail=0 error=0 files=1

Usage

verify takes any mix of files and directories and walks directories recursively. convert rewrites a single input.

terminal
gopdfrab verify docs/                     # verify every PDF under a directory
gopdfrab verify --json report.pdf         # machine-readable output
gopdfrab verify --detail report.pdf       # every page and object per issue
gopdfrab convert in.pdf out.pdf           # rewrite towards PDF/A-1b
gopdfrab convert --profile pdfa2b in.pdf  # or towards PDF/A-2b
gopdfrab convert --dpi 300 in.pdf         # tune the raster fallback
gopdfrab verify --max-decoded-mb 64 x.pdf # cap decoded stream output at 64 MB

Exit codes

0Conformant — every file passed.
1Non-conformant — at least one file failed.
2Error — usage, open, or I/O failure.

Flags

Accepted by both verify and convert.

--profilepdfa1b | legacy1b | pdfa2b | pdfDefault pdfa1b. legacy1b is the strict Isartor reading; pdf runs object-model checks only.
--passwordstringFor encrypted input. Prefer GOPDFRAB_PASSWORD, since flags show up in ps.
--max-decoded-mbintMax decoded size of one stream. Default 256.
--max-resident-mbintMax cache memory per document. Default 64.
--jsonboolJSON output.
--detailboolList every page and object per issue instead of grouping.

convert flags

--dpiintRaster fallback resolution. Default 150.
--max-iterationsintMax verify/fix passes. Default 4.
-opathOutput path. Default: input with .pdfa.pdf (or .fixed.pdf for the pdf profile).

--profile pdf skips PDF/A and runs only the ISO 32000 object-model checks. convert prints rasterized:, dropped: and lost: lines for anything the conversion cost. A conformant result can still have lost content, so read them.

JSON

terminal
# verify --json emits an array of {path, error?, result?}
gopdfrab verify --json docs/ | jq -r '.[] | select(.result.valid == false) | .path'
report.json

CI

check-pdfa.sh
#!/usr/bin/env bash
# Fail the build when any PDF under docs/ is not PDF/A-1b conformant.
set -euo pipefail

if gopdfrab verify docs/; then
  echo "all documents are conformant"
else
  status=$?
  if [ "$status" -eq 1 ]; then
    echo "::error::one or more documents are not PDF/A-1b conformant"
  else
    echo "::error::gopdfrab failed to run"
  fi
  exit "$status"
fi