I am using Mathematica to plot a number of figures I require and then using them as pdfs in Latex.
The issue is that Mathematica exports the figures using Acrobat 5.x settings compatibility and I think this results in figures that are large, not optimized and when I have a couple of them in the final pdf, sometimes it takes minutes just to print a single page of the final document.
Is there a way to change the output settings for pdfs in Mathematica?
Should I export as pdfs, convert to postscripts and then create new pdfs from the .ps with new settings?
Should I export .eps and convert to pdf?
Is there an one step way to create optimized pdfs through Mathematica?
Quick example (and a bit exaggerated so the difference is quite obvious): The pdf I export from Mathematica (Export[“C:/figure.pdf”, %]) is 1065kb in size, .pdf ->.ps ->.pdf gives a final file of 652kb and .eps->.pdf a file of 610kb.
I would not use any of these in a latex but it shows the difference in the settings.
It is a myth that
pdf->ps->pdfwill always give you a smaller file size. For e.g., consider(in mathematica)
(in the shell)
test.pdfis 446kB, whereastest1.pdfis a whopping 11.5MB on my machine!What happens normally, is that when you export a PDF file using Mathematica, it stores the text (axes tick marks, labels, etc), fonts and images, all of which add to the bulk. If you have vector graphics with lots of tick marks/labels, these can be quite significant. Doing
pdf->ps->pdfwill strip the file of font data and text data, at the same time compressing the image, which is why you see a decrease in file size. Although not observable at small magnifications, you will notice the difference when you zoom in considerably. For e.g., replacingpwithproduces a 37kB file for
test.pdfand an 8kB file fortest1.pdfon my machine. The quality of the 8kb file is poorer than the original (zooming to 600%+ shows this). You can see the plain text information that mathematica stores in the PDF file by doingHowever, for more complicated PDF files, converting to
psand then back topdfis not necessarily a good option and can result in the file size blowing up.You can try playing with the options for PDF in
Export, such as"AllowRasterization"andImageResolution, or even rasterize the image before saving, but I guess you already knew that.Here’s a back-alley quick and dirty way of reducing file size from within mathematica
The file size is now only 12kB! It’s only a third of the original, only slightly larger than that obtained from
pdf->ps->pdf, and is of a much better quality than the 8kB one (although not exactly the same as the original. The differences can be seen at magnifications of 1200% and above).What happens is that upon importing and re-exporting, only the stored image is saved. The plain text part of it is thrown away, and in this small example, that happened to be significant. For the
DensityPlotexample, the reduction was only to 425kB (still, went down rather than blow up to 11MB).