I am trying to convert a pdf containing grayscale pictures and black text into shades of a single color in cmyk color space (for printing). I was thus very happy to learn, from a side remark in one of Heiko Oberdiek's answers about the key decodearray of \includegraphics, which lets us specify a linear transformation on each channel of the given color space. This key places the appropriate /Decode array in the pdf file, and colors are converted when displaying or printing the pdf file.

The approach works fine for grayscale or rgb images, but fails for cmyk images, and here is why. There are two kinds of cmyk color spaces (or of cmyk jpg images?): one for which white is all zeros and one for which it is all ones. To invert colors, pdfTeX uses a /Decode array which maps the interval [0,1] to [1,0] in each channel. This second /Decode array overrides ours. See a recent answer of mine for more details.

The question is to know how I can remove the second /Decode array, or otherwise include a cmyk image with altered colors. My current solution is to post-process the pdf, replacing the second /Decode array by spaces.

Some code: first build a cmyk image

convert `kpsewhich example-image.jpg` -colorspace cmyk /tmp/example-image-cmyk.jpg

then include it

\includegraphics[decodearray={1 1 0 0 1 0 0 1}]{example-image-cmyk.jpg}

and run pdflatex on this file. Afterwards, look at the pdf file and find the /Decode key twice in the same dictionary, and replace the second one by /Xxxxxx (or whatever key, with the same length). The pdf now has new colors.

EDIT: From an email discussion of pdfTeX developpers 6 years ago, it seems that providing the colorspace keyword to the primitive underlying \includegraphics may help.

  • isn't it similar to this question: tex.stackexchange.com/q/146517/2891 ?
    – michal.h21
    Dec 16 '13 at 19:06
  • I don't think it is the same, as the other question attempts to reproduce a specific image in a pdf, while I am trying to alter colors in an existing image when including it in the pdf. Dec 18 '13 at 10:57
  • Just for completeness, the very useful decodearray undocumented feature of graphicx has been excised from the package, so that the technique can no longer be used even on b/w or rgb images. Dec 20 '17 at 13:50
  • 1
    @StevenB.Segletes decodearray was never excised from graphicx, it was added to graphicx.sty in the 2017/06/25 release Jan 5 '18 at 0:47
  • @DavidCarlisle Well son-of-a-gun, I probably need to update my installation at the office. Jan 5 '18 at 1:29

Old question but as I just saw it:

A low-level solution seems to be possible. If one use the colorspace keyword the default /Decode array is not inserted and one can add it manually:

\immediate\pdfobj { /DeviceCMYK }
\pdfximage width 100pt attr{/Decode [1 1 0 0 1 0 0.2 0.4]} 
           colorspace \deviceobjnum
\pdfrefximage \pdflastximage\quad
\pdfximage width 100pt attr{/Decode [1 1 0.5 0.5 1 0 0.2 0.4]}
           colorspace \deviceobjnum
\pdfrefximage \pdflastximage


enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.