[Tex/LaTex] Inkscape SVG with opacity exported to PDF in pdflatex document not displayed correctly on Mac OS X

inkscapemacpdftexsvgtransparency

I use Inkscape to create graphics which I export to PDFs in order to include them into a LaTeX documents (with \includegraphics and using pdflatex). I didn't notice that there is something wrong until someone told me that my figures do not display correctly on Mac OS X. Basic graphic parts, e.g. boxes or circles which have a Opacity setting less than 100% are not displayed at all.

The problem seems to be in pdflatex since the exported PDF from inkscape alone displays just fine on a Mac. Since I'm using Linux and sometimes Windows I never realized that there is even a problem!

After trying to figure out what could cause the problem, i stumbled over

\includegraphics PDF, color problem
and
Inkscape → PDF → includegraphics → XeLaTeX → changed colors

However, this did not solve my problem.

A similar question was asked in Opaque-to-transparent gradient lost in embedded PDF figure but now answer was really given.

I found out that the conversion of the exported PDF to a PS and then back to PDF resolves the issue but the graphic quality is quite bad afterwards.

What did I miss? Thanks for any suggestion.

Below is a minimal working example:

\documentclass[a4paper]{article}
\usepackage[pdftex]{color,graphicx}

\begin{document}

\begin{figure}[htb]
 \begin{center}
  \includegraphics[width=\columnwidth]{test_diagram}
  \caption{Block diagram created with Inkscape 0.48}
 \end{center}
\end{figure}

\end{document}

The included graphic can be downloaded here: https://www.dropbox.com/s/mrtj0c3u0ng6a39/test_diagram.pdf

Inkscape: 0.48.3.1 r9886
pdfTeX, Version 3.1415926-2.4-1.40.13 (TeX Live 2012/Debian)

Best Answer

I have seen this problem as well if Inkscape images are embedded via pdflatex and then displayed on on a PDFKit-based viewer. (PDFKit is the built-in PDF rendering engine of OS X and used by Skim, Preview, and many other programs).

Apparently, Inkscape has an "unusual" way of specifying transparencies, which do not survive the embedding done by pdflatex.

The only workaround that has reliably worked for me is to "sanitize" the PDF by flattening the transparencies. I use ghostscript (via the ps2pdfwr script) with the dHaveTransparencies=false switch for this purpose:

ps2pdfwr -dCompatibilityLevel=1.4 -dHaveTransparency=false test_diagram.pdf sanitized.pdf

The downside is that this comes down to rasterizing the image. The default resolution for this is 720 dpi, which should be fine for most use cases. If, however, you need better (or lower) quality you can specify the resolution as well:

ps2pdfwr -dCompatibilityLevel=1.4 -r1200 -dHaveTransparency=false test_diagram.pdf sanitized.pdf

At 1200 dpi, your ~5 KiB image increases to ~78 KiB in its rasterized version. However, PDF transparencies are a source of many strange problems if it comes to output devices – not only if produced by Inkscape. See, for instance: Using opacity in TikZ makes the entire page become "more coarse" when printed. Hence, I consider this as the price to pay.

Related Question