9

When I print a report I get an error:

An error exists on this page. Acrobat may not display the page correctly. Please contact the person who created the PDF document to correct the problem

After a lot of debugging, I've found that this MWE reproduces the problem. I've tried it on three different computers with the same error.

\documentclass{standalone}          
\usepackage{tikz}
\usepackage{ctable}
\begin{document}
\begin{tikzpicture}
\filldraw[opacity=.5] (0,0) rectangle (1,1);
\end{tikzpicture}
\end{document}

When loading the ctable package, the image is changed (the opacity disappears), so it seems the error comes from some incompatibility between ctable and opacity in tikz. The error only appears when trying to print though, acrobat before attempting to print. (Printing either to a pdf file or to a real printer)

I have the following versions of tikz and ctable:

tikz.sty 2013/12/13 v3.0.0
ctable.sty 2014/04/25 v1.29

How can I fix this?


EDIT: I found the warning Transparency disabled: incompatible with tikz package from ctable so I guess this incompatibility can explain the error in the first MWE.

However, I continued digging and found that the spy library seem to be incompatible with ctable as well.

Here's an MWE that generates the same error when printing (either to a pdf file or to a real printer):

\documentclass{standalone}          
\usepackage{tikz}
\usetikzlibrary{spy}
\usepackage{ctable}
\begin{document}
\begin{tikzpicture}[spy using outlines={size=2cm,connect spies}]
\begin{scope}
\spy on (-3,.25) in node at (2,0);
\end{scope}
\end{tikzpicture}
\end{document}

There seem to be a serious problem with using tikz + ctable, can it be fixed?

  • If you look at the documentation if it sees that tikz is loaded it gives up on the transparency hence it is not a bug but a choice. A strange choice I would say. Do you need to use ctable? – percusse Jul 2 '15 at 20:16
  • @percusse I see. The second example with the spy-library is then probably a totally unrelated issue. I don't need to but it would be nice to avoid changing all the tables in the report (I noticed this error quite late in the project, haven't printed the report for proofreading earlier). – Grimler Jul 2 '15 at 20:33
10

Package ctable loads package transparent. Both package transparent and tikz implements transparency. This needs access to a page resource, a dictionary ExtGState for the transparent values. Unhappily, the LaTeX format has overslept the PDF development quite entirely. Managing global resources is the prime task for an OS, format in TeX speek. Because of the missing resource manager, both packages do what most packages do, they think they are alone and add their stuff to the resource, \pdfpageresources in this case. The result for

% PDF file without compression for easier reading/analyzing
\pdfobjcompresslevel=0
\pdfcompresslevel=0

\documentclass{standalone}
\usepackage{tikz}
\usepackage{transparent}
\begin{document}
\begin{tikzpicture}
\filldraw[opacity=.5] (0,0) rectangle (1,1);
\end{tikzpicture}
\end{document}

PDF object 4 contains the Resources for the page (reformatted):

4 0 obj
<<
  /ColorSpace 3 0 R
  /Pattern 2 0 R
  /ExtGState 1 0 R % by TikZ, see next object
  /ExtGState <<    % by package transparent
    /TRP1 << /ca 1 /CA 1 >>
  >>
  /ProcSet [ /PDF ]
>>
endobj

1 0 obj
<<
  /pgf@CA.5 << /CA .5 >>
  /pgf@ca.5 << /ca .5 >>
>>
endobj

As can be seen, the dictionary Resources (object 4) contains two entries ExtGState, which is not allowed by the PDF specification. Now it's up to the PDF reader, how it resolves the issue and which entry is used. Thus its by accident, if the PDF works for which program/printer. If the transparency of both packages are used in the page, then there will be always an error, because one of the ExtGState is missing at any case. Otherwise there is a 50:50 chance, that the PDF viewer/printer picks the unused ExtGState and throws away the other.

If you do not need the transparency of ctable/transparent, then you can fool LaTeX in thinking, that transparent is already loaded:

\makeatletter
\@namedef{ver@transparent.sty}{}
\makeatother
\usepackage{ctable}

Package ctable could provide an option for turning transparency off.

Patch for transparent to use package pgf's resource management

The following patch is applied after package transparent is loaded. Then it cooperates with package pgf by using the macro \pgfutil@addresource@extgs for the transparent settings and the transparency methods of both packages can be used.

\documentclass{standalone}
\usepackage{tikz}
\usepackage{transparent}

\makeatletter
\begingroup\expandafter\expandafter\expandafter\endgroup
\expandafter\ifx\csname pgfutil@addpdfresource@extgs\endcsname\relax
\else
  \AtBeginDocument{%
    % \pgf@sys@addpdfresource@extgs@plain{%
    \pgfutil@addpdfresource@extgs{%
      \TRP@list
    }%
  }%  
  \let\TRP@addresource\relax
\fi
\makeatother

\begin{document}
Hello \texttransparent{.3}{World}
\begin{tikzpicture}
\filldraw[opacity=.5] (0,0) rectangle (1,1);
\end{tikzpicture}
\makeatletter 
\end{document}

Also the disabling of \transparent by package ctable can be undone. The warning remains, but can be ignored.

\documentclass{standalone}
\usepackage{tikz}
\usepackage{transparent}
\let\OriginalTransparent=\transparent

\makeatletter
\begingroup\expandafter\expandafter\expandafter\endgroup
\expandafter\ifx\csname pgfutil@addpdfresource@extgs\endcsname\relax
\else
  \AtBeginDocument{%
    % \pgf@sys@addpdfresource@extgs@plain{%
    \pgfutil@addpdfresource@extgs{%
      \TRP@list
    }%
  }%
  \let\TRP@addresource\relax
\fi
\makeatother

\usepackage{ctable}
\AtBeginDocument{%
  \let\transparent=\OriginalTransparent
}

\begin{document}
Hello \texttransparent{.3}{World}
\begin{tikzpicture}
\filldraw[opacity=.5] (0,0) rectangle (1,1);
\end{tikzpicture}
\makeatletter
\end{document}
  • This fixed it! Awesome. It would, imho, perhaps be a good idea to mention this "trick" in the ctable documentation, do you think it would be a good idea to suggest this to the maintainer? – Grimler Jul 2 '15 at 20:43
  • 1
    @Grimler I plan to update transparent to cooperate with pgf/TikZ. – Heiko Oberdiek Jul 2 '15 at 21:32
  • This example does not work any more. Add \usepackage{scrlfile} and change \usepackage{ctable} to \AfterPackage{tikz}{\usepackage{ctable}} – Peter Ebelsberger Jul 12 '16 at 6:27
  • @PeterEbelsberger Make a bug report for ctable. The error message after \usepackage{tikz,transparent,ctable} with You must load ctable after tikz is wrong, since ctable is loaded after tikz. Also there is another logic error, ctable looks for package transparent, but defines a dummy \transparent in some situation, which causes an already defined error message, when transparent is loaded later. – Heiko Oberdiek Jul 12 '16 at 17:17
  • 1
    @HeikoOberdiek Bugreport sent by email to the maintainer... – Peter Ebelsberger Jul 17 '16 at 13:50

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.