Consider this code:

data = Table[Sin[j^2 + i], {i, 0, Pi, Pi/3}, {j, 0, Pi, Pi/3}];
p1 = Graphics[Raster[data], Frame -> True, FrameStyle -> Large, 
  ImageSize -> 300];
p2 = ListDensityPlot[data, InterpolationOrder -> 0, 
  ColorFunction -> "GrayTones", Frame -> True, FrameStyle -> Large, 
  ImageSize -> 300];
Export["~/Downloads/1.pdf", p1, ImageResolution -> 100]
Export["~/Downloads/2.pdf", p2, ImageResolution -> 100]

Why does the font in the first plot appear vectorized while the the font in the second does not?

enter image description here enter image description here


remove the ImageResolution option will vectorize both plots, but ImageResolution is very helpful in reducing the pdf file size and I can't give up on that.

Export["~/Downloads/1.pdf", p1]
Export["~/Downloads/2.pdf", p2]

enter image description here enter image description here

  • 1
    $\begingroup$ This is not an answer, but the same thing happens when exporting these graphics as EMF or WMF. $\endgroup$ – Verbeia Jun 20 '13 at 4:47
  • 1
    $\begingroup$ Possible duplicate of this question. $\endgroup$ – m_goldberg Jun 20 '13 at 10:49
  • $\begingroup$ version or system issue? I get vectors in both cases w/v9 on windows. $\endgroup$ – george2079 Jun 20 '13 at 17:29
  • $\begingroup$ By the way, exporting to EPS i see in both cases the entire file is 'vector', i.e. each square is drawn and filled. You might try exporting eps and converting externally. $\endgroup$ – george2079 Jun 20 '13 at 17:40

A possible answer to the question in the title, "How can I get vectorized text when exporting to pdf?" is the same as what I suggested here:

rasterTrick[plot_] := 
  Prolog -> {Opacity[0], Texture[{{{0, 0, 0, 0}}}], 
    VertexTextureCoordinates -> {{0, 0}, {1, 0}, {1, 1}}, 
    Polygon[{{0, 0}, {.1, 0}, {.1, .1}}]}]

Export["~/Downloads/1.pdf", p1 // rasterTrick]

The function rasterTrick is described in the linked answer, and you'll notice that the white lines between the exported gray squares are gone. The density plot has been turned into a bitmap at high resolution, but the frame labels are not rasterized.

So the Export command just needs to be augmented by //rasterTrick.

  • $\begingroup$ Thanks for the help, but the problem seems to be the ImageResolution options. Only use Export["~/Downloads/2.pdf", p2], the frame labels are also not rasterized. $\endgroup$ – xslittlegrass Jun 20 '13 at 17:27
  • $\begingroup$ Yes, that's correct. But your reason for adding ImageResolution is to get a better quality density plot, without the white lines, right? I see no other reason to use ImageResolution in the first place. My trick achieves this improvement in quality, as if you had used ImageResolution -> 200, but it applies rasterization only to the plot contents and not to the axes or frames. It's a hack that I discovered by accident, but it's better than ImageResolution here. $\endgroup$ – Jens Jun 20 '13 at 17:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.