How to Compress a pdf file

Summary

dvips or pdf2ps
ps2pdf -dPDFSETTINGS=/screen file.ps file_screenoptimised.pdf

Introduction... how and why to compress?

There are open source and commercial applications available to compress those large pdf files. On windows I used Adobe Acrobat usefully, Adobe are the originators of the pdf format and there software is the defacto standard.

It's often a problem with files made by Latex with large figures that the file size can become quite large, usually the native files will be kept in original format, or even converted into large ps files when compiling with the latex command, resulting in huge postscript or pdf files that are not appropriate for sharing. Usually the tools to compress pdf files are already available on linux and mac systems, and it's also possible to install them on windows. You will need to have ghostscript availble, this provides a lot of tools including ps2pdf and pdf2ps.

Main matter -- how to compress those pdf files on command line?

For those wanting to distribute latex documents in pdf file format, it is possible to leave all optimisation of the file to the last step. More complex ways are possible, like having different versions of the image files available, this is a quick and easy way.

latex command generates dvi file.

dvips command generates ps file.

ps2pdf command generates pdf file.

More about ps2pdf command

ps2pdf has a lot of possible options for file optimisation. The option -dPDFSETTINGS= provides several sets of defaults to generate output similar to the acrobat distiller program in windows and mac (of course in linux you also have flexibility to specify every other option too if you wanted).

For example;

  • ps2pdf file.ps file.pdf generates big file
  • ps2pdf -dPDFSETTINGS=/screen file.ps file_screenoptimised.pdf generates small file suitable for reading on computer screen only
  • ps2pdf -dPDFSETTINGS=/ebook file.ps file_ebookoptimised.pdf generates slightly larger file with higher resolution graphics suitable for ebook readers

Alternative way, avoiding generating the ps file

Following linuxaria.com

After install ghostscript on your machine, then using following command; gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/ebook -dNOPAUSE -dQUIET -dBATCH -sOutputFile=output.pdf input.pdf

PDFSETTINGS options

The following options are available for dPDFSETTINGS depending on the desired resolution of the output.

-dPDFSETTINGS=/screen   (screen-view-only quality, 72 dpi images)
-dPDFSETTINGS=/ebook    (low quality, 150 dpi images)
-dPDFSETTINGS=/printer  (high quality, 300 dpi images)
-dPDFSETTINGS=/prepress (high quality, color preserving, 300 dpi imgs)
-dPDFSETTINGS=/default  (almost identical to /screen)

Comments

This content originally appeared on my bainite blog, you can find / make comments there: Optimising your pdf file with latex, dvips and ps2pdf.

Conclusion

Compressing file can be achieved with commands dvips or pdf2ps to make a ps file, then ps2pdf with appropriate options.