13

I am trying to produce a pdf in a CMYK colorspace with an additional spotcolor, and make sure black on a spotcolor background is "overprinted", i.e. that if I look at the color separation of the resulting pdf, the background color channel should be solid, not with cutouts for the characters printed on top of the background.

I found the colorspace package which appears to have this functionality, but I can't seem to get it to work. I may very well be overlooking something obvious, but if I compile:

\documentclass{article}
\usepackage{lipsum}
\usepackage[overprint]{colorspace}
\usepackage{tikz}  %% (Almost) works when not loading TikZ
\definespotcolor{spot}{Spotcolor}{0,1,0,0}

\begin{document}

\pagecolor{spot!50}

\lipsum[1]

\overprintstate{1}

\lipsum[1]

\end{document}

I get a resulting pdf-file which looks like this in Acrobat

enter image description here

Hiding the black channel, I see

enter image description here

I would have expected (at the very least) that the second paragraph would not have cutouts for the characters. (Unticking the "Simulate overprint" option in Acrobat has no apparent effect on anything.)

Any ideas how I might get this to work?


Update

It looks this is a clash with TikZ. Compiling the same document without loading TikZ, (almost) everything works as I expect. Without TikZ, I get overprinting (but I can't seem to turn overprinting off with \overprintstate{0} -- I'll do some more experimenting, perhaps this only works on a page by page basis).

My original document is very complex and relies heavily on TikZ, so ideally I would like for this to work even with TikZ.

  • 4
    Note for other prospective commenters: This is a very good question, involving advanced features. It is clearly described, and I believe it is important. Having enough of a graphics art background (and Acrobat Pro) I understand the question. Alas, I cannot answer it. Reason for my comment: Please don't mark this as off-topic. – user139954 Dec 7 '17 at 22:16
  • 1
    Does the example work without loading TikZ? – Heiko Oberdiek Dec 8 '17 at 3:00
  • 1
    @HeikoOberdiek Good point. Originally I had a more complex example, and eventually I want this to work with TikZ (the real document is very complex and relies heavily on TikZ). It turns out that it (almost) works without loading TikZ. I'll update the question. – mrf Dec 8 '17 at 6:42
  • @mrf Can you eventually add to your question that the feature you use is only available in Adobe Acrobat Pro and not in Adobe Acrobat Standard? – Matthias Dec 8 '17 at 7:08
  • 1
    It works for me if I load tikz before colorspace. – Ulrike Fischer Dec 8 '17 at 8:46
11

Both packages tikz and colorspace add an entry /ColorSpace to the page resources, from the generated PDF file:

11 0 obj % Page object
<<
  /Type /Page
  /Resources 10 0 R
  ...
>>
endobj

10 0 obj % Page resources
<<
  /ColorSpace 7 0 R
  /Pattern 6 0 R
  /ExtGState 5 0 R
  /ColorSpace 9 0 R
  /Font << /F8 13 0 R >>
  /ProcSet [ /PDF /Text ]
>>
endobj

7 0 obj % /ColorSpace from package tikz
<<  /pgfprgb [/Pattern /DeviceRGB] >>
endobj

9 0 obj % /ColorSpace from package colorspace
<< /&Spotcolor 8 0 R >>
endobj

The problem is in the dictionary for the page resources. It contains the key /ColorSpace twice. But the PDF specification does not allow duplicate keys and one of them has to be ignored by the PDF reader.

Correct would be one key /ColorSpace with a merged color space dictionary, e.g.:

10 0 obj % Page resources
<<
  /ColorSpace 7 0 R
  ...
>>
endobj

7 0 obj % Color space dictionary
<<
  /pgfprgb [/Pattern /DeviceRGB]
  /&Spotcolor 8 0 R
>>
endobj

Both packages do not know each other. At least TikZ has a macro to add new color space entries, from pgfsys-pdftex.def:

\pgfutil@addpdfresource@colorspaces{ /pgfprgb [/Pattern /DeviceRGB] }

Then, the macro \spc@pagecs can be changed to use the TikZ macro instead:

\documentclass{article}
\usepackage{lipsum}
\usepackage[overprint]{colorspace}
\usepackage{tikz}
\definespotcolor{spot}{Spotcolor}{0,1,0,0}

% Patch macro \scp@pagecs from package colorspace to use
% macro \pgfutil@addpdfresource@colorspaces from pgf/TikZ
% for adding the color space to the page resources.
\makeatletter
\def\spc@pagecs#1{%
  \ifx\spc@currcs\@empty\else
    \edef\tempa{%
      \noexpand\spc@remcs\the\pdfpageresources
      \noexpand\spc@remcs{\spc@currcs}}%
    \tempa
  \fi
  \let\spc@tempd\@empty % list with known spaces
  \@for\spc@tempa:=#1\do{%
    \ifx\spc@tempa\@empty\else
      \spc@dospaces\spc@tempa
      \spc@unknown{spc@ir@\spc@tempa}{color (space) `\spc@tempa'}%
      \edef\spc@tempd{,\spc@tempd,\spc@tempa,}%
    \fi}%
  \let\spc@tempb\@empty % elements in /ColorSpace
  \let\spc@tempc\@empty % name for macro (\..&..&) with pdf ref
  \def\spc@elt##1##2{%
    \@expandtwoargs\in@{,##2,}{\spc@tempd}%
    \ifin@
      \protected@edef\spc@tempb{%
        \spc@tempb\@nameuse{spc@ir@##2}\space}%
      \protected@edef\spc@tempc{%
        \spc@tempc\@nameuse{spc@ir@##2}&}%
    \fi}%
  \spc@csall % Uses \spc@elt
  \@ifundefined{spc@cs@\spc@tempc}{%
% PATCH: the following two lines are deleted:
%    \immediate\pdfobj{<< \spc@tempb>>}%
%    \expandafter\xdef\csname spc@cs@\spc@tempc\endcsname{\the\pdflastobj}%
    \expandafter\xdef\csname spc@cs@\spc@tempc\endcsname{not empty}% PATCH: added
  }{}%
  \expandafter\let\expandafter\spc@currcs\csname spc@cs@\spc@tempc\endcsname
  \ifx\spc@currcs\@empty
  \else
% PATCH: the following four lines are deleted:
%    \edef\spc@tempa{\pdfpageresources{%
%      \the\pdfpageresources\space/ColorSpace
%      \@nameuse{spc@cs@\spc@tempc} 0 R%
%    }}%
    \pgfutil@addpdfresource@colorspaces{\spc@tempb}% PATCH: added
  \fi
}
\makeatother

\begin{document}

\pagecolor{spot!50}

\lipsum[1]

\overprintstate{1}

\lipsum[1]

\end{document}
  • Thank you. This sounds convincing and looks promising, but it doesn't work for me. I still get the cutout in the spotcolor channel. (On the other hand, if I load TikZ before colorspace, as Ulrike suggested, it seems to work for me.) Which version of pdftex and colorspace are you using? – mrf Dec 8 '17 at 21:19
  • @mrf colorspace: 2015/06/01 v1.1.0, 2006/11/15 v1.2 (2006 should very likely be 2016), pdfTeX: 3.14159265-2.6-1.40.17. – Heiko Oberdiek Dec 8 '17 at 23:17

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.