# PDF exports of ArrayPlot's are fuzzy (OS X)

[The following problem occurs on OS X; I don't know if it also occurs with other OS's.]

If I produce a Graphics object with ArrayPlot, right-click on it, choose "Save Graphic As...", and save it as a PDF file, the resulting PDF graphic is absurdly fuzzy/blurry (which is particularly perverse, considering that it is among the simplest kind of graphics (all solid-color squares with vertical and horizontal edges).

For example, in the PNG screenshot below, one such figure is shown in the Mathematica GUI (on the left), and the PDF file exported as described above (and displayed at "Actual Size" magnification with the Preview app) is shown on the right:

(Actually, the screenshot of the original on the left looks fuzzier to me than what I actually see on the screen, but that degree of fuzziness is nothing compared to what the PDF looks like.)

As I understand it PDF is the native graphics format for OS X. It should be possible (not to say trivial) to save this very simple graphic as a PDF in a way that preserves all the edges and corners to infinite resolution.

Does anyone know how?

PS: FWIW, I did try displaying the Graphics object above with Style[#, Antialiasing->False]&, but this change had no effect, either on the resulting PDF nor on the object's appearance in the Mathematica GUI.

-
Does the same thing happen if you use Export["file.pdf", ArrayPlot[(* stuff *)]]? –  Guess who it is. Sep 29 '12 at 16:13
@J.M. Yes, same problem. The only difference this time is that, when this second PDF is displayed at "Actual Size" magnification, the plot has the same size as it does in the Mathematica GUI. –  kjo Sep 29 '12 at 16:25
This is a problem with Preview.app, not Mathematica. Try opening it in Adobe Reader or ghostview and it'll look correct –  The Toad Sep 29 '12 at 16:51
note that pl = ArrayPlot[Table[i - j, {i, 5}, {j, 5}]]; Export["pl.pdf", pl]; produces a non fuzzy array (macos 10.7 preview). –  chris Sep 29 '12 at 17:45
@rm-rf: Thanks! If you post your comment, I'll by happy to accept it. –  kjo Sep 29 '12 at 19:41

This is a problem with Preview, the PDF reader included in OS X. The problem does not show when using other PDF readers (not based on PDFKit) such as Adobe Reader.

To prevent blurring you just need to untick the "Smooth text and line art" checkbox under "Viewing documents" in Preview's preferences:

However, this will lower the quality of text and line art as well.

-

Actually, the problem is with Mathematica's export, at least with Version 10.

I have been saving a file wit MatrixPlot (using Save As...-> PDF), and have encountered the same problem.

Turns out, MatrixPlot (and similar) data is being exported as a bitmap, which gets blurred in Adobe Reader 9 (which I have), even if "Smooth line art" and "Smooth images" is unchecked in preferences. The PDF showed fine in Okular, but that is probably just the lack of smoothing in that viewer.

I have found the solution on Inkscape forums. Open the PDF file in a text editor, and locate the following line:

/Interpolate true

Change it to the following:

/Interpolate false

Et voilà! The problem is solved, and the PDF shows fine in Adobe Reader, without blurring.

I have not found a setting in Mathematica to affect the value of this option on export to PDF.

-
Under Windows I do not see the Interpolate word in the PDF file even after uncompressing the streams inside it by the command qpdf --stream-data=uncompress in.pdf out.pdf. The PDF file is generated in MMa 10.0.1 by the command Export["in.pdf", MatrixPlot[{{1, 2, 1}, {3, 0, 1}, {0, 0, -1}}]]. –  Alexey Popkov Nov 19 '14 at 9:46
I'm using Mathematica 10.0.0 for Linux 64-bit, which version do you have? –  Romwell Nov 19 '14 at 20:22
I have MMa 10.0.1 under Win7 x64. –  Alexey Popkov Nov 19 '14 at 20:25
I wonder if they simply fixed it in an update. –  Romwell Nov 19 '14 at 20:27

In version 9 of Mathematica, if you export the graphics by right clicking and choosing Save As..., the problem does not occur. Unfortunately this will cause other problems. It's a tradeoff you need to consider.

If the figure is simple enough, it may be a good workaround, but keep an eye on the width of the frame and tick marks: they may be off.

-