[Tex/LaTex] Reduce pdf file size for large image produced by pgfplots

file sizepdfpgfplotsviewers

I created a plot using pgfplots. The plot is embedded in a document. The total size of the document is about 26 MB, while the plot is 12.5 MB.

The plot contains a lot of data which makes the pdf file quiet large, 12.4 MB in fact (Note: this is also caused due to the fact that I use the spy library of tikz). This causes the pdf reader become a bit slow when you look at the pag which includes the figure. The biggest problem I have is when I want to print the .pdf when using Adobe Acrobat. When I try to print it using Envince no problems occur. Because the document is most likely to be published I want to fix this, since (unfortunately) a lot of people use Adobe Acrobat.

Now I am wondering what the best approach would be for reducing the file size

  1. I can choose to remove data from the plot
  2. I can choose to convert the pdf to an image format, like .jpg or .png
  3. Try to reduce the .pdf file size, http://www.wikihow.com/Reduce-PDF-File-Size, which I tried
  4. …?

Now I am wondering what the best approach would be.

Option 1 is not really possible since I want to keep the data, most of the plots are on top of each other and due to the fact that each plot has a certain opacity level you see the concentration where they bundle.

Option 2 is possible however than I loose the vector format. Zooming in in a pdf viewer would become pixely. The document which includes the figure is very likely to be published so I am not sure if I want this.

Option 3 I tried this but it only reduces the filesize with a few MB's, from 12.5 MB to 9 MB, so not that much.

For people that are interested the pdf file of the figure: https://dl.dropboxusercontent.com/u/20782274/pato_scenario_1_dataloss06_output.pdf

Best Answer

Procedure for printing export of single image PDFs:

  1. convert/export it to svg

    inkscape -l reduce_temp.svg pato_scenario_1_dataloss06_output.pdf

  2. generate HiDPI images: 1200dpi - common home printer resolution, 4800 - won't see much difference

    inkscape --export-png=reduce_out_1200.png --export-dpi=1200 reduce_temp.svg

    inkscape --export-png=reduce_out_2400.png --export-dpi=2400 reduce_temp.svg

    inkscape --export-png=reduce_out_4800.png --export-dpi=4800 reduce_temp.svg

  3. convert it to pdf:

    convert reduce_out_1200.png reduce_out_1200.pdf

    convert reduce_out_2400.png reduce_out_2400.pdf

    convert reduce_out_4800.png reduce_out_4800.pdf

Results:

 ls -lh reduce_* pato_scenario_1_dataloss06_output.pdf 
-rw-r----- 1 miroslav miroslav  12M Feb 10 15:44 pato_scenario_1_dataloss06_output.pdf
-rw-r--r-- 1 miroslav miroslav 657K Feb 10 16:10 reduce_out_1200.pdf
-rw-r--r-- 1 miroslav miroslav 918K Feb 10 16:07 reduce_out_1200.png
-rw-r--r-- 1 miroslav miroslav 1.5M Feb 10 16:10 reduce_out_2400.pdf
-rw-r--r-- 1 miroslav miroslav 2.0M Feb 10 16:09 reduce_out_2400.png
-rw-r--r-- 1 miroslav miroslav 3.2M Feb 10 16:11 reduce_out_4800.pdf
-rw-r--r-- 1 miroslav miroslav 4.3M Feb 10 16:08 reduce_out_4800.png
-rw-r--r-- 1 miroslav miroslav  26M Feb 10 16:05 reduce_temp.svg

Procedure if you want images inside a PDF with text description, ie. not only plot image in PDF:

This has still one downside, it converts text into raster. It is good for printing, but bad for viewing using PC.

  1. generate PDF/SVG plot images
  2. convert them to HiDPI png images
  3. include these images in TeX file

You can see, that it provides (almost) loss-less conversion even on 1200DPI, 1500% scale: enter image description here

Also, it keeps size of image, 100% scale:

enter image description here

Procedure for text + image + fixed view in computer

  1. generate just plot graph images without any text in them
  2. convert them to HiDPI png images
  3. create figures - add description, plot axes, etc... paste PNG/raster image over it in TeX file. It is little bit harder to create, but it's possible.