# Using opacity in TikZ makes the entire page become “more coarse” when printed

In my document, some of the figures uses opacity. In the PDF viewer, everything looks fine, but when I print the document, the pages in which these figures appear become more "coarse"; the text looks darker and not as smooth.

Is this something that can be fixed in TikZ or LaTeX, or is this printer-related?

EDIT: Although I have not verified this example (don't have access to the printer at the moment), I believe this will produce the same result nonetheless:

\documentclass[a4paper, 11pt]{article}

\usepackage[T1]{fontenc}
\usepackage[fulloldstylenums]{kpfonts}
\usepackage{microtype}
\usepackage{lipsum}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}
\node [%
draw,
rectangle,
fill=black,
minimum size=5cm,
opacity=0.5,
] {};
\draw [semithick] (6cm, 0cm) -- (8cm, -2cm);
\end{tikzpicture}
\lipsum[5]
\end{document}


## Without opacity:

As I said, it doesn't look as if there is a difference, but when printed the one with opacity should appear "coarser": the text is not as smooth, and diagonal lines will become thicker. Again, I haven't been able to verify this exact example yet (I'm most interested in testing this on the printer that I printed my document on, and it is located at my work).

-
Please give a minimal working example. Anyway, I think that it is probably printer related. for quick test you try to make a screenshot and print this screenshot. – someonr Jan 4 '12 at 16:35
@someonr: I've included an example that I think will show this effect, but I've been unable to test it yet. – gablin Jan 4 '12 at 17:55
I don't seem to be able to tell any difference, if there is any, it is too small to notice. It may depend on your pdf viewer, in addition to the printer. – Jan Hlavacek Jan 4 '12 at 20:34
Which version of pdftex are you using? It might be related/similar to the problem described here: tex.stackexchange.com/questions/16061/… – matth Jan 5 '12 at 10:18
Does adding \usepackage[cmyk]{xcolor} to your preamble make any difference? – matth Jan 5 '12 at 10:23

Transparency effects are a relatively new feature for PDF (≥ 1.4) and many printers do not yet support it "out of the box" (basically, this requires a PostScript Level 3 RIP with additional PDF 1.4 extensions). So the printing system (printer driver) has to "flatten" transparency effects by rasterizing objects into ordinary CMYK objects before sending them to the printer.

Rasterizing is usually done page-wise: The complete page is rasterized into a bitmap and then send to the printer. This also effects the other content of the page, resulting in the observed "coarse appearance" of the text.

(Note: The effect may as well be the same with printers that claim to support PostScript Level 3 with PDF 1.4, but performs a similar transformation just inside the printer. One really has to check with the actual printer.)

Workaround

The way out would be to flatten transparency effects in PDF graphics before embedding them into the document, so that the printer driver has no reason to rasterize a whole page. Adobe provides a white paper with some background info and how to achieve this with their products. My approach would be to use ghostscript to convert the respective images to PDF 1.3:

ps2pdf13 image.pdf image-13.pdf


Unfortunately, ghostscript also just rasterizes the page, so the fonts inside the image will still get the "coarse appearance" and their text is no longer selectable in the resulting image. (This is also the reason that transforming the complete document to PDF 1.3 before printing is not an option. Maybe the Adobe tools do a better job here.)

You need separate PDFs of your graphics, so TikZ images have to be compiled into PDFs and included with \includegraphics. Martin Scharrer's standalone class may be helpful for this.

Seamless Integration for TikZ

The conversation to PDF1.3 could also be performed seamlessly by (mis-)using the TikZ Externalization Library (PGF Manual 2.1, pp. 343ff). In short, "this library provides a high-level automatic or semi–automatic export feature for TikZ pictures. Its purpose is to convert each picture to a separate pdf without changing the document as such."

The good thing is that this conversion process can easily be customized (thanks to Andrew Stacey for this hint!) to a sequence of arbitrary commands with the external/system call key. Whatever PDF eventually comes out of this process will be used.

To figure out the best sequence of commands for a particular printer, one could also use the default external/system call setting and manipulate the generated PDF for the figure (which usually has a name like \jobname-figureXXX.pdf) manually. It will then be used (and not overwritten) in the next compilation with pdflatex.

The following MWE also demonstrates how implicit rasterizing can be enabled and disabled with \tikzexternalizeenable and \tikzexternalizedisable. It has to be compiled with the -shell-escape option given to pdflatex:

\documentclass[a4paper, 11pt]{article}

\usepackage[T1]{fontenc}
\usepackage[fulloldstylenums]{kpfonts}
\usepackage{microtype}
\usepackage{lipsum}
\usepackage{tikz}

% setup externalization
\usetikzlibrary{external}
\tikzexternalize
\tikzexternaldisable
\tikzset{external/system call={%
pdflatex \tikzexternalcheckshellescape -halt-on-error -interaction=batchmode -jobname "\image" "\texsource";
ps2pdf13 "\image".pdf "\image-13".pdf && cp "\image-13".pdf "\image".pdf}}

\begin{document}

% figure uses opacity, enable rasterizing through externalization
% (in the resulting PDF this is observable by the nonselectable node text)
\tikzexternalenable
\begin{tikzpicture}
\node [%
draw, rectangle, fill=black,
minimum size=5cm, text width=5cm,
opacity=0.5,
text=white,
] {Nonselectable Text:\\Figure has been rasterized};
\draw [semithick] (6cm, 0cm) -- (8cm, -2cm);
\end{tikzpicture}
\tikzexternaldisable % back to default

\lipsum[5]

\begin{tikzpicture}
\node [%
draw=black!50, rectangle, fill=black!50,
minimum size=5cm, text width=5cm,
text=white,
] {Selectable Text:\\Figure has not been rasterized};
\draw [semithick] (6cm, 0cm) -- (8cm, -2cm);
\end{tikzpicture}
\end{document}


I have no printer at hand to test the result. However, printing this page should not lead to a "coarse appearance" of the text (sans the rasterized figure, of course):

-
I'm not convinced that PostScript's transparency support (even in PS 3++) is the same as PDF's - e.g. I can not find anything about alpha channel support in PRLM3 or PS3010/3011. – Martin Schröder Jan 5 '12 at 10:36
@MartinSchröder: Right, I was mislead by the info in Adobes white paper. Apparently, newer printers have a "PostScript Level 3 RIP with Support for PDF 1.4 extension", so they speak "PostScript", but additionally provide some features necessary to print PDF 1.4. I will edit the answer accordingly. – Daniel Jan 5 '12 at 10:40
I've deleted my comments as they are no longer relevant. – Loop Space Jan 10 '12 at 9:57
Not too long ago, I reprinted the document on another printer, and there I didn't see this problem. Guess it's a printer thing, then. – gablin Mar 1 '12 at 11:45
@Daniel, when using ps2dpf13 is there any way to set the image resolution? I tried both ps2pdf13 -dPDFSETTINGS=/printer and ps2pdf13 -dColorImageResolution=300 without success. – Luigi Mar 5 '14 at 8:59

This is just a guess, but if it is a colour printer, based on similar problems I've had myself (in non-LaTeX contexts) the difference may be one of true black vs rich black. Printers with CYMK inks will use the ("true") blacK ink for large B&W areas (e.g., text blocks) but create a "rich" black by mixing together colours for black bits in regions that use colour (e.g., diagrams). Sometimes the printer will make this change on a page-by-page basis, so even a tiny bit of colour on an otherwise monochrome page will cause the whole page to be printed in colour. And sometimes even a grey region like the one you have here (which could equally well be printed with a lighter coverage of black ink) will trigger it. If your entire page, including the text, is printed in "rich" black, it will certainly look coarser than one printed with real black ink, since all the fine bits will have to be printed several times in different inks which will not overlap perfectly.

If my hypothesis is correct, this has nothing to do with opacity per se, and you would get the same result with a coloured square, say fill=red. In this case, you may be able to solve the problem by explicitly choosing "B&W" in the printer settings (i.e., turning off the use of the CYM inks).

This post has ended up rather OT for this site... I may delete it if it turns out not to solve your problem!

-
That's an interesting theory. Unfortunately, it is incorrect. First, the affected pages do not have any color whatsoever. Second, pages with color don't show this phenomenon. So, I still believe that it's the opacity which is the cause, in one way or another. – gablin Jan 5 '12 at 8:52
I think Adobe Reader has a feature "always print text in black" that can be enabled/disabled. – matth Jan 5 '12 at 10:29

I just had the same problem. If your figure is not too complex, you can also solve this by changing the order in which you display things (think of a "Send to Back" option), so you can mimic transparency. So in your example, instead of using the opacity option, just fill with

fill = black!50


which is 50% black, and make sure you put your rectangle before (i.e., behind) anything you want to appear on top of it.

-