How to reduce the size of a pdf file?
I'm looking for a way in Ubuntu to reduce the size of a pdf (by reducing the quality of the images).
I know that this can be done in Ghostscript by typing the following command in terminal:
gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/screen -dNOPAUSE -dQUIET -dBATCH -sOutputFile=output.pdf input.pdf
The problem is that I can't specify the quality with any accuracy. The parameter -dPDFSETTINGS=/screen
is the one that decides the quality; but the alternatives are quite rigid (for example it is possible to do -dPDFSETTINGS=/ebook
for slightly better quality).
I'm looking for a way to reduce the size of a pdf in a way that allows me to specify the desired quality numerically.
Solution 1:
I was able to make a slight variation on your command successful using the -r300 option from @drN The -r option allows you to set the output resolution in the pdf as well as png.
gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/default \
-dNOPAUSE -dQUIET -dBATCH -dDetectDuplicateImages \
-dCompressFonts=true -r150 -sOutputFile=output.pdf input.pdf
Solution 2:
The simplest way I found is to open source PDF file with LibreOffice Draw and then export to PDF with expected DPI. Export dialog window of Draw allows you to specify DPI and other options for exported PDF.
Solution 3:
These two posts that I had posted on Stackoverflow should help you. I was trying to reduce the size of pdfs whilst ensuring that they met a certain dpi or ppi for my thesis.
Reducing size of pdf with ghostscript
Changing pdf image dpi using gs
Have you tried playing around with convert
in Linux?
Edit:
gs \
-o out300.png \
-sDEVICE=pngalpha \
-r300 \
input.pdf
If I remember correctly, r300
is the output dpi
but you might want to check. This converts a pdf to a png, though.
OR
convert -units PixelsPerInch myPic.pdf -density 300 fileout.pdf
Let us know how it goes! This is for a pdf or any other format to any other format. I just used an input file of myPic.pdf and an output file of fileout.pdf
Solution 4:
If reducing the size of the file is your primary objective (and not only reducing size of the figures and also not to specify the quality numerically), how about ps2pdf
:
ps2pdf input.pdf output.pdf
Depending on the characteristics of the PDF, this can reduce the file size by an order of magnitude.