10

So I have 2D plot, made with DensityListPlot. Mathematica just cannot export them properly to PDF, so what I want to do is 1) export the plot itself, without axes, labels, etc, as a jpg image, and 2) Inset this image in an empty graphics containing only axes, labels etc. So far so good.

The problem is that when I export the final graphics to PDF, the image are not compressed at all -- and the file end up weighing 400k instead of 30k.

The question is: how do I specify the format and compression factor of images embedded in a pdf?

VividD
  • 3,660
  • 4
  • 26
  • 42
Mammouth
  • 101
  • 3
  • Rasterize the image first maybe? – fizzics Oct 10 '12 at 10:07
  • This is precisely what I do, but Export does not compress the raster image. – Mammouth Oct 10 '12 at 10:36
  • Print to CutePDF http://www.cutepdf.com/ (it's free). – Chris Degnen Oct 10 '12 at 10:38
  • 4
    Thanks Chris. I used gs instead of cutepdf to optimise the PDF, and it works very well. Still Wolfram really need to improve PDF export of 2D graphics... – Mammouth Oct 10 '12 at 10:59
  • 1
    Have you taken a look at [http://mathematica.stackexchange.com/questions/3190/saner-alternative-to-contourplot-fill], [http://mathematica.stackexchange.com/questions/1542/exporting-graphics-to-pdf-huge-file], [http://mathematica.stackexchange.com/questions/3926/printing-exported-pdf-graphics-fails]? My guess is that the size of the file is dictated by the JPEG. Have you tried compressing the JPEG that you export? – tkott Oct 10 '12 at 14:01
  • 1
    @Mammouth I'm not quite sure why you believe the raster images aren't compressed, but they most certainly are. If you look in the file you can clearly see the /FlateDecode filter applied to the image stream. This is a lossless compression method so it does not achieve as high a compression ratio as a lossy method (like JPEG). – ragfield Oct 10 '12 at 14:45
  • 1
    @ragfield: fair enough. But how do I tell Mathematica to use jpeg ? – Mammouth Oct 11 '12 at 19:21

1 Answers1

5

Try using EPS as export format (e.g. Export["filename.eps", img], then converting the resulting file to PDF with epstopdf or ps2pdf. This produces much better results than Mathematica's PDF export in most cases.