How to embed an image plot with scaled dimensions in a pdf without smoothing effects?

2

I need to produce an image plot of data as a pdf. There are a small number of pixels in the data (roughly 100 x 100), so each pixel is discernible (not a smooth image). I have tried exporting a pdf with a couple different scientific computing programs, but when I view the pdf in OS X Preview or Firefox's pdf.js plugin the data looks bad. Each individual pixel of data looks like it has been broken into about five pixels along one dimension and three along the other (the aspect ratio is not 1:1 in the figure) and these subpixels have slightly different colors, so the data is being blurred. I tried opening the pdf in Inkscape and it looks fine there. From Inkscape, I determined that the data is being embedded as a 100x100 pixel png, which looks fine in Preview when I extract it from the pdf and view it on its own.

So, what is the best option for getting a pdf with a sharp data plot? For now, I am going to create an oversampled png of the data and embed that into pdf. I don't like this solution too much because it makes the figure file size unnecessarily large and still means the image is blurry when you zoom in. Should it be possible to get the pdf to render a stretched image without smoothing? Are my scientific computing programs (Igor Pro and MATLAB) not formatting the pdf properly, or are Preview and Firefox not rendering it properly by smoothing it?

ws_e_c421

Posted 2013-02-02T18:17:38.000

Reputation: 169

Answers

1

Okay, I finally found the answer to this question in a couple posts on the TeX section of stackexchange: My pixel perfect picture gets blurry when compiled in LaTeX and Included PNG appears blurry in PDF.

Summary of those posts: many PDF viewers have an optional setting to smooth PDF output ("Smooth text and line art" in OS X Preview, "Anti-alias text and line art" in Skim; some programs like Firefox's pdf.js extension have this setting on without an obvious way to disable it; others like Google Chrome's pdf viewer do not seem to have this setting; note that the Preview and Skim setting names are misleading because raster images, not just line are, are smoothed if this setting is enabled). For the programs that do have this setting, disabling the setting makes the embedded image look good, but other aspects of the pdf (and other pdfs) will not look as good (text will be pixelated etc.). The PDF format does not have an internal option for telling the viewer program not to anti-alias an element (perhaps one day...), so it seems like for now the solution I described above is actually the method that is typically used for embedding pixelated images into pdfs: oversample the image to the required resolution*.

The other option is to convert the image into a vector image of colored rectangles. I experimented with this method with Inkscape (use the trace option of the tile clone method to clone a single pixel rectangle over the image; see this documentation page for some of the details), but because this method requires specifying all of the coordinates of each pixel's rectangle object it ends up being much less efficient disk space wise compared to embedding a raster image.

* One way to oversample an image is to use ImageMagick with the sample flag setting the dimensions to higher multiples of the base image's dimensions. Note that you need a \! after the new dimensions if you want to change the aspect ratio (e.g. if you stretch out the image in the pdf, you might want to make each original pixel ten pixels wide but only three pixels high).

ws_e_c421

Posted 2013-02-02T18:17:38.000

Reputation: 169