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.


9 Answers 9


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

Edit: Newer versions now prevalaent of gs have a shorter syntax:

gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/default \
    -dQUIET -dDetectDuplicateImages \
    -dCompressFonts=true -r150 -o output.pdf input.pdf

Thanks @pierre-adrien

  • 11
    This command transformed a 25MB 4-pages PDF into the almost same quality one, but 2MB. Cheers! May 28, 2015 at 0:57
  • 1
    This works with most files. However, in some cases it actually increases the file size. It seems the -r option is ignored in these cases. Mar 2, 2017 at 18:49
  • 2
    This command consumed all of my RAM (8Gb) and froze my laptop with a 1000page pdf file.
    – To Do
    Sep 30, 2019 at 7:32
  • 7
    This didn't work for me. No matter what value I use with -r, it always gives me an output with approximately the same size as the original (I am compress to convert a scanned PDF).
    – giusti
    Sep 15, 2020 at 15:46
  • 1
    For a shorter command, you could replace -dNOPAUSE -dBATCH -sOutputFile=output.pdf input.pdf with -o output.pdf input.pdf (-o switch documentation: ghostscript.readthedocs.io/en/gs10.0.0/Use.html#o-switch) Mar 28 at 11:12

The simplest way I found is to open the source PDF file with LibreOffice Draw and then export to PDF with the expected DPI.

The export dialog window of Draw allows you to specify the DPI and other options for the exported PDF.

  • 4
    I tried all the other command line things, but in the end, this allowed me to raise the compression enough for my purposes.
    – C.Rogers
    Nov 15, 2016 at 17:54
  • 3
    The graphical way, with still a lot of control.
    – Agmenor
    Nov 22, 2016 at 14:41
  • I found out that LibreOffice Draw is better at printing/exporting pdf than just about anything else, so +1.
    – Yoric
    Jul 24, 2019 at 16:04
  • 6
    For large-font documents like certificates a DPI of 100 and JPEG compression of 80% seems to produce the best size-quality trade-off. I could reduce a 12 MB document to 110KB. Nov 5, 2020 at 11:15
  • Wow, this is a very simple and yet effective solution: I just reduced a scanned PDF from 49 MB to <4MB!
    – Peter T.
    May 6, 2023 at 8:33

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?


gs \
  -o out300.png \
  -sDEVICE=pngalpha \
  -r300 \

If I remember correctly, r300 is the output dpi but you might want to check. This converts a pdf to a png, though.


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

  • 1
    Hmm... I looked at the questions you linked to. They are interesting, but it is difficult to eke out a concrete command that I should use. I'm looking for a command with some numerical value there that I can play with that will determine the quality. Can you effect such a command? Can one do it using convert?
    – Nicole
    Oct 28, 2012 at 3:11
  • I editted my answer to include some more simpler options. Take a look and let us know! :)
    – dearN
    Oct 28, 2012 at 13:10
  • 2
    The convert increases my pdf size, even if I use a 100 dpi. Maybe the best choice is to convert to png using "gs" and then "convert" to go to pdf?
    – Nicole
    Oct 28, 2012 at 19:15
  • @Nicole There have always been issues with pdf conversions. What do you propose to use the pdf for?
    – dearN
    Oct 28, 2012 at 19:26
  • @Nicole I noticed that to get the best result for pdfs/eps files, I'd have to go back to the program that made the pdf in the first place and change my save options to save in the dpi/ppi that I want. I hope that helps and yes that can be a bit of a pain the backside.
    – dearN
    Oct 28, 2012 at 19:31

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.

  • 1
    Amazing suggestion. So easy, and my PDF just went from 13.7 MB to 2.5 MB - and it still looks the same to me! Feb 18, 2022 at 9:05
gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/screen -dNOPAUSE -dQUIET -dBATCH -sOutputFile=myNewFile.pdf myOldFile.pdf

This is the easiest way I think, can reduce the size to 50+/- kb. On your terminal, go to the directory of the file: example

cd ~/document/files

Then type the above code where:


is the file's new name and


is the name of the file.


You can use ocrmypdf --oversample <DPI> flag to reduce the size of the pdf.

For example:

ocrmypdf --skip-text --oversample 150 input.pdf output.pdf

I usually like to do this:

ocrmypdf --skip-text --oversample 150 input.pdf input.pdf

to save time for renaming the pdf file. I chose dpi to be 150 as reference to ghostscript flag -dPDFSETTINGS=/ebook.


You can use the gs command as suggested by others, but make sure you change dPDFSETTINGS to either screen, for low quality images (75 dpi), or ebook, for 150 dpi.

Here's a full list of the dPDFSETTINGS to choose from (based on this link):

  • -dPDFSETTINGS=/screen — Low quality and small size at 72dpi.

  • -dPDFSETTINGS=/ebook — Slightly better quality but also a larger file size at 150dpi.

  • -dPDFSETTINGS=/prepress — High quality and large size at 300 dpi.

_ -dPDFSETTINGS=/default — System chooses the best output, which can create larger PDF files.

You use a command like the following:

gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/ebook \                                                                                                                                     
    -dNOPAUSE -dQUIET -dBATCH -dDetectDuplicateImages \
    -dCompressFonts=true -sOutputFile=output.pdf input.pdf 

From my answer to a similar Unix & Linux Stack Exchange question:

If the PDF file consists entirely of image data;

pdftk inputFile.pdf burst
mogrify -density 300 -format jpg -quality 20 pg_*.pdf
convert *.jpg -auto-orient outputFile.pdf

The density value can match the density of the source image (eg 300 dpi), but the jpeg quality should be lower than the source image (e.g. 20).

pdf2ps large.pdf very_large.ps
ps2pdf very_large.ps small.pdf

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .