Ghostscript PDF/A ICC Profiles Safer Mode Validation

Ghostscript PDF/A Errors: ICC Profiles, SAFER Mode and Validation

The Problem and Exact Symptom

pdfwrite prints PDF/A processing aborted, output may not be a PDF/A file. and still writes a PDF that contains no /OutputIntents entry. The prefix file PDFA_def.ps failed before attaching the output intent, so veraPDF, KDP, and IngramSpark preflight treat the result as ordinary PDF.

Exact Fix

Replace the placeholder ICC line in PDFA_def.ps, whitelist that exact file, then run the flags in this order:

% PDFA_def.ps — replace the shipped placeholder "(srgb.icc)"
/ICCProfile (/usr/share/color/icc/colord/sRGB.icc) def
gs -dPDFA=2 -dBATCH -dNOPAUSE -sDEVICE=pdfwrite \
   -sColorConversionStrategy=RGB \
   -dPDFACompatibilityPolicy=1 \
   --permit-file-read=/usr/share/color/icc/colord/sRGB.icc \
   -sOutputFile=out-pdfa.pdf \
   PDFA_def.ps in.pdf

Copy PDFA_def.ps from your Ghostscript lib directory into the working directory before editing. It must appear before in.pdf on the command line, because it is a prefix file.

Flag / Setting What It Does Required or Optional
-dPDFA=2 Selects PDF/A-2b; 1 = PDF/A-1b, 3 = PDF/A-3b Required
-dBATCH Exits after the last input file instead of opening the GS> prompt Required
-dNOPAUSE Suppresses the per-page prompt Required
-sDEVICE=pdfwrite Selects the PDF writer device Required
-sColorConversionStrategy=RGB Converts colour to RGB so it matches the 3-channel sRGB intent Required
-dPDFACompatibilityPolicy=1 Ignores non-PDF/A operations with a warning instead of writing them (0) or aborting (2) Required
--permit-file-read=<absolute path> Whitelists the ICC file for reading under the default -dSAFER sandbox Required
-sOutputFile=out-pdfa.pdf Output path; never point it at in.pdf Required
/ICCProfile (...) def Absolute profile path streamed into {icc_PDFA} Required
PDFA_def.ps before in.pdf Builds /OutputIntents and the /GTS_PDFA1 intent dictionary Required
-dNOSAFER Disables the file sandbox; replaces --permit-file-read= Optional fallback

Windows (gswin64c)

gswin64c -dPDFA=2 -dBATCH -dNOPAUSE -sDEVICE=pdfwrite ^
  -sColorConversionStrategy=RGB -dPDFACompatibilityPolicy=1 ^
  --permit-file-read=C:/icc/sRGB.icc ^
  -sOutputFile=out-pdfa.pdf PDFA_def.ps in.pdf

Use forward slashes inside the PostScript string as well: /ICCProfile (C:/icc/sRGB.icc) def. Backslashes are escape characters in PostScript strings and silently corrupt the path.

Linux / Docker: locate the real files

gs -h | grep -A4 'Search path'
find /usr/share/ghostscript -name PDFA_def.ps
find /usr/share -name 'sRGB*.icc' -o -name 'default_rgb.icc'

Slim images frequently ship no system ICC profiles; Ghostscript’s own iccprofiles/default_rgb.icc is valid for the RGB intent. If a locked-down wrapper blocks path whitelisting, substitute -dNOSAFER for --permit-file-read= and change nothing else.

Why It Happens and Tool Edge Cases

  • -dSAFER became the default in Ghostscript 9.50. PDFA_def.ps opens the profile from PostScript via ICCProfile (r) file. Files named on the command line are readable; files opened inside PostScript are not. The read raises /invalidfileaccess, the prefix file aborts, and no output intent is ever created.
  • Wrong switch prefix: -s instead of -d. -sPDFACompatibilityPolicy=1 defines a string. pdfwrite reads a numeric definition, so it silently keeps default policy 0, emits warnings, and writes non-compliant content. Only -dPDFACompatibilityPolicy=1 takes effect.
  • Placeholder or mismatched ICC profile. The shipped /ICCProfile (srgb.icc) entry is relative and resolves against the process working directory, not the input PDF’s folder. A CMYK profile (4 components) paired with -sColorConversionStrategy=RGB (3 components) also breaks the intent setup.
  • Producer content that PDF/A forbids. InDesign exports carrying live transparency fail under -dPDFA=1; transparency is only legal from PDF/A-2 onward. Headless LibreOffice and Pandoc→LaTeX pipelines can emit unembedded fonts, encryption, or JavaScript. Policy 2 aborts on any of these; policy 1 drops the operation and continues.
  • Common Mistake That Breaks the Fix: assuming the corrected path inside PDFA_def.ps is sufficient, or that -I and the input directory cover it. -I extends the library search path only. Every file opened from PostScript needs its own --permit-file-read= entry, absolute, spelled identically in both places a whitelist for /data/job/ does not authorize /usr/share/color/icc/.

Verification and Rollback

Back up the prefix file, then re-run with stderr captured:

cp PDFA_def.ps PDFA_def.ps.bak
gs -dPDFA=2 -dBATCH -dNOPAUSE -sDEVICE=pdfwrite \
   -sColorConversionStrategy=RGB -dPDFACompatibilityPolicy=1 \
   --permit-file-read=/usr/share/color/icc/colord/sRGB.icc \
   -sOutputFile=out-pdfa.pdf PDFA_def.ps in.pdf 2> gs.log
echo "gs exit=$?"
grep -F 'PDF/A processing aborted' gs.log && echo STILL_BROKEN || echo PDFA_SETUP_OK
verapdf --flavour 2b --format xml out-pdfa.pdf > report.xml

Expected: gs exit=0, PDFA_SETUP_OK, no /invalidfileaccess or undefinedfilename in gs.log, and a veraPDF verdict of compliant against the PDF/A-2B profile with zero failed rules. Warnings about dropped operations are acceptable under policy 1; the abort string is not.

Structural spot check when veraPDF is unavailable:

mutool show out-pdfa.pdf trailer/Root

The catalog must contain an /OutputIntents key, and the referenced intent must carry /S /GTS_PDFA1 plus /DestOutputProfile. An absent /OutputIntents means the prefix file still failed, regardless of exit status.

Rollback, restore the untouched prefix file and return to plain PDF output:

cp PDFA_def.ps.bak PDFA_def.ps
gs -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -sOutputFile=out-plain.pdf in.pdf

in.pdf is never modified in place because -sOutputFile names a separate file. Deleting out-pdfa.pdf, gs.log, and report.xml restores the pre-fix workspace state.

You may also like

See All Posts →