0

I am trying to generate a PDF using a library called wkhtmltopdf to create an RGB pdf. I am then using ghostscript to convert it to a CMYK format, however, the black text that is in the pdf is not pure black [cmyk(0,0,0,1)].

The black color is visible in other channels.

The command for ghostscript is:

gs -dBATCH -dNoOutputFonts -dNOPAUSE -dTextBlackPt=1 -dBlackPtComp=1 -sTextICCProfile -dNOCACHE -sDEVICE=pdfwrite -sProcessColorModel=DeviceCMYK -sColorConversionStrategy=CMYK -sOutputICCProfile=ps_cmyk.icc -sDefaultRGBProfile=srgb.icc -dOverrideICC=true -dRenderIntent=1 -sOutputFile=cmyk11.pdf test-rgb-cmyk.pdf

Any help would be massively appreciated! Been at this for a few days now. Thanks!

Ghostscript version: 9.26 Example pdf: https://drive.google.com/file/d/1nSM05b0O6fEb_0Z1rr2REbOPQAdwolTA/view?usp=drivesdk

Varun Joshi
  • 599
  • 2
  • 9
  • 24
  • Here's a similar [question](https://stackoverflow.com/questions/21751887/convert-pdf-to-cmyk-but-ignore-black) from 2014. – Igor Jul 25 '19 at 11:16

2 Answers2

1

Almost all the switches you are using will have no effect with the pdfwrite device, they are specific to rendering devices (bitmap output). In particular the -dTextBlackPt, -dBlackPtComp and TextICCProfile will do nothing.

In order to properly colour manage the conversion you need to specify input and output ICC profiles. If memory serves, you need to alter the default Gray, RGB and CMYK profiles that Ghostscript uses.

Really I'd need to see an example file (as simple as possible) and it would obviously be useful to know which version of Ghostscript you are using. If it's not the current version then I'd suggest you upgrade anyway.

halfer
  • 19,824
  • 17
  • 99
  • 186
KenS
  • 30,202
  • 3
  • 34
  • 51
  • Hey Ken! Thanks for your answer. I've edited the question with an example pdf and gs version – Varun Joshi Jun 08 '19 at 05:43
  • 1
    I'm going to have to consult with our colour expert, it looks to me like this needs a custom ICC profile for the input RGB colours. – KenS Jun 10 '19 at 08:32
  • Concerning specifying output ICC profile: according to my experiments ([general summary](https://bugs.ghostscript.com/show_bug.cgi?id=701022), [specifically about `OutputICCProfile`](https://bugs.ghostscript.com/show_bug.cgi?id=700931#c3)) it has no effect as well. – Igor Jun 12 '19 at 16:56
  • Concerning the "custom ICC profile for the input RGB colors" - this sounds much like [this](https://stackoverflow.com/a/35646895/1032586) collink-based solution. Sadly, personally, I've [not managed](https://stackoverflow.com/questions/35596346/ghostscript-convert-pdf-into-cmyk-preserving-pure-black-for-text#comment100970828_35646895) to make it work. – Igor Jul 27 '19 at 17:00
  • You're almost certainly going to have to create your own ICC profile, I very much doubt that an existing one will work. OTOH I'm not the colour expert. – KenS Jul 28 '19 at 08:10
0

Examples of Ghostscript commands to convert PDF from sRGB or eciRGB_v2 to eciCMYK_v2 (FOGRA 59) while keeping black plain (K only), not rich (CMYK)

I managed to convert PDF file in RGB to CMYK while keeping RGB black #000000 plain K black, not rich CMYK black.

DeviceLink ICC had to be created from e.g. eciRGB_v2 (or sRGB, if your source is sRGB) profile to the appropriate CMYK profile using collink tool (from argyll package) with the "-f" attribute to hack the black colors.

Ghostscript is then called with a control file declaring use of the profile and its parameters.

Example of making the DeviceLink RGB to CMYK profile

collink -v -f eciRGB_v2.icc eciCMYK_v2.icc eciRGB_v2_to_eciCMYK_v2.icc

Example of a control file to map eciRGB_v2 to eciCMYK_v2 (control-eciRGB_v2.txt)

Image_RGB   eciRGB_v2_to_eciCMYK_v2.icc 0   1   0
Graphic_RGB eciRGB_v2_to_eciCMYK_v2.icc 0   1   0
Text_RGB    eciRGB_v2_to_eciCMYK_v2.icc 0   1   0

(note must be separated by tabs, not spaces)

Sample ghostscript command to do the actual conversion

gs -o 2-output-cmyk-from-eciRGB.pdf \
       -sDEVICE=pdfwrite \
       -sColorConversionStrategy=CMYK \
       -sSourceObjectICC=control-eciRGB_v2.txt \
       1-input-rgb.pdf