I’m trying to convert arbitrary PDF files (a magazine created with pdfLaTeX, containing some photos, but also some graphics such as webcomics) to valid PDF/X-3 using Ghostscript and I want the result to be in grayscale/monochrome. I don’t know a lot about ICC color profiles and I don’t really care about color management in any case, so if this easier without ICC profiles, then I don’t mind. I’m willing to let the printer do their thing with my file – I don’t need absolute color fidelity (especially since we’re talking about grayscale here).

I’ve been trying to get it to work using the Ghostscript documentation, section “Creating a PDF/X-3 document”. Based on that, my attempt looks like this:

gs                                   \
  -dSAFER -sDEVICE=pdfwrite          \
  -dEmbedAllFonts                    \
  -sProcessColorModel=DeviceGray     \
  -sColorConversionStrategy=Gray     \
  -dPDFX -dPDFACompatibilityPolicy=1 \
  -o 'output.pdf' -f 'my_pdfx_def.ps' 'input.pdf'

Where my_pdfx_def.ps contains the following, based on the template that comes with Ghostscript:


systemdict /ProcessColorModel known {
  systemdict /ProcessColorModel get dup /DeviceGray ne exch /DeviceCMYK ne and
} {
} ifelse
{ (ERROR: ProcessColorModel must be /DeviceGray or /DeviceCMYK.)=
  /ProcessColorModel cvx /rangecheck signalerror
} if

[ /GTS_PDFXVersion (PDF/X-3:2002) % Must be so (the standard requires).
  /Trapped /False                 % Must be so (Ghostscript doesn't provide other).
  /DOCINFO pdfmark

% Define an ICC profile:

currentdict /ICCProfile known {
  [/_objdef {icc_PDFX} /type /stream /OBJ pdfmark
  [{icc_PDFX} <</N systemdict /ProcessColorModel get /DeviceGray eq {1} {4} ifelse >> /PUT pdfmark
  [{icc_PDFX} ICCProfile (r) file /PUT pdfmark
} if

% Define the output intent dictionary:

[/_objdef {OutputIntent_PDFX} /type /dict /OBJ pdfmark
[{OutputIntent_PDFX} <<
  /Type /OutputIntent              % Must be so (the standard requires).
  /S /GTS_PDFX                     % Must be so (the standard requires).
  /OutputCondition (Commercial and specialty printing) % Customize
  /Info (none)                     % Customize
  /OutputConditionIdentifier (CGATS TR001)      % Customize
  /RegistryName (http://www.color.org)   % Must be so (the standard requires).
  currentdict /ICCProfile known {
    /DestOutputProfile {icc_PDFX}  % Must be so (see above).
  } if
>> /PUT pdfmark
[{Catalog} <</OutputIntents [ {OutputIntent_PDFX} ]>> /PUT pdfmark

This does run and produces a file that superficially seems OK in my PDF viewer. However, I’m not sure that this is actually enough (producing a valid/sensible PDF/X-3 document) considering the long list of things I’m supposed to do according to Ghostscript’s documentation. In particular, it says

To create a PDF/X-3 document from a Postscript or a PDF file, you should :


  • Specify a PDF/X definition file before running the input document. It provides additional information to be included into the output document. A sample PDF/X definition file may be found in gs/lib/PDFX_def.ps.
  • If a registered printing condition is applicable, specify its identifier in the PDF/X definition file. Otherwise provide an ICC profile and specify it in the PDF/X definition file as explained below.

I tried adapting the file PDFX_def.ps it mentions (see above), but I don’t know what an OutputCondition is or what I’m supposed to put for that. Unfortunately, this is barely documented in the Ghostscript docs. I tried setting an .icc file in my customized version, but couldn’t get Ghostscript to find that file – no matter what, I always got “Error: /invalidfileaccess in --file--”. And which color profile would I be using, anyway?

  • Provide a DefaultRGB resource file in the ColorSpace resource category. Either define it in the PDF/X definition file, or provide a definition of gs/Resource/ColorSpace/DefaultRGB. gs/Resource/ColorSpace/DefaultRGB is usually distributed with Ghostscript, its content may not necessarily satisfy your needs, see below.

Needless to say, it doesn’t specify how to do this. But in any case, do I even need this considering I want grayscale?

  • Specify, using -sOutputICCProfile, an ICC profile which represents the color space (either CMYK or Gray) of the final file. This is the same ICC profile used in the PDF/X definition file as the ICCProfile. Even if you are using a standard OutputCondition and do not need to specify an ICCProfile, you must still set OutputICCProfile with an appropriate ICC profile in order for proper color conversion.

Well, I didn’t specify -sOutputICCProfile and that didn’t seem to do any harm. Should I still? (Again, where am I supposed to pull the ICC profile out from?)

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.