# Inkscape SVG with opacity exported to PDF in pdflatex document not displayed correctly on Mac OS X

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

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}


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

-
I was able to get the LaTeX output figure to render on a Mac by first opening the PDF in Acrobat Pro, then re-saving it as an optimised PDF with Transparency enabled. This leads me to believe that your software (Inkscape) MAY have a save (or export) setting that can do the same... –  commonhare Mar 17 at 18:20
@commonhare, thanks for pointing that out. Since converting the PDF to a PS and than back to a PDF works as well (pdf2ps test_diagram.pdf tmpPS.ps; ps2pdf tmpPS.ps test_diagram.pdf) ,but the image gets rasterized. I thought that there should be an export option in inkscape. Unfortunately, these options are quite limited and I don't have much experience with it. I played around with them but without any luck –  xlr8t Mar 17 at 21:12

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.

-
thanks for this input. I didn't know about ps2pdfwr. The result is pretty much the same as using pdf2ps and then ps2pdf but with the flexibility of defining the resolution. However, its kind of sad that we have to live with that. The question for me is, if this is a problem of Inkscape or one from the rendering engine of OS X. –  xlr8t Mar 17 at 21:22
@xlr8t: Or maybe one of pdflatex, as the Inkscape image itself renders fine? Sorry, but I don't really know. However, given the printing problems on many printers when using transparencies, I have made it a habit to rasterize the respective images. –  Daniel Mar 17 at 21:47
you are right, it might be pdflatex since the inkscape image itself renders fine. –  xlr8t Mar 18 at 16:11