


  • 1
    it depends on what consumes the space...need a lot more information. compressing image space could help, but if you're trying a large file heap spray, that won't work. seriously need more info. – RobotHumans Mar 16 '12 at 17:14
  • 1
  • 1

21 Answers 21




| improve this answer | |
  • 18
  • That is not necessarily true. If the content went from an image to text, that is more than fessible. [That is assuming that the text is accurately ocred] – monksy May 16 '15 at 20:11
  • 3
    I recommend you shrinkpdf.sh script, you can customize the code to use the ppi value you want (72 by default) and reach exactly the filesize you need to sacrifice the least quality. This made me able to upload a scanned document of 11 MB with a max. size of 3 MB without losing a lot of quality. – Severo Raz Apr 9 '16 at 22:18
  • 6
    shrinkpdf works great! – AmanicA Feb 22 '17 at 22:14
  • 3
    Where is the ghostscript shell that the OP is referring to askubuntu.com/questions/113544/…? – user13107 Mar 5 '18 at 6:44

Use the following ghostscript command:

  • -dPDFSETTINGS=/screen lower quality, smaller size. (72 dpi)
  • -dPDFSETTINGS=/ebook for better quality, but slightly larger pdfs. (150 dpi)
  • -dPDFSETTINGS=/prepress output similar to Acrobat Distiller "Prepress Optimized" setting (300 dpi)
  • -dPDFSETTINGS=/printer selects output similar to the Acrobat Distiller "Print Optimized" setting (300 dpi)
  • -dPDFSETTINGS=/default selects output intended to be useful across a wide variety of uses, possibly at the expense of a larger output file
| improve this answer | |
  • 10
  • 9
  • 42
  • 7
    gs available configuration parameters: ghostscript.com/doc/current/Ps2pdf.htm – Antonios Hadjigeorgalis Dec 11 '14 at 23:41
  • 4
    on 17.10 it made 42 mb pdf to 127 mb :( – YaSh Chaudhary Oct 23 '17 at 3:24


ps2pdf input.pdf output.pdf

This also directly works on pdf's, as suggested in the comments.

Some users also report more success when using the ebook settings as follows:

ps2pdf -dPDFSETTINGS=/ebook input.pdf output.pdf 
| improve this answer | |
  • 5
  • 17
  • 1
  • 4
    This bypasses password protection...just sayin' – jojo Jan 6 '15 at 20:28
  • 10
    ps2pdf will take pdfs as inputs, so you can do this in one step: ps2pdf intput.pdf output.pdf – frabjous Sep 1 '16 at 19:19

If you have a pdf with scanned images, you can use convert (ImageMagick) to create a pdf with jpeg compression (You can use this method on any pdf, but you'll loose all text informations).

For example:

convert -density 200x200 -quality 60 -compress jpeg input.pdf output.pdf

Adjust density (e.g. 100x100) and quality to your needs.

Depending on your input jpeg compression might not be the best choice due to compression artifacts. You have the choice between BZip, Fax, Group4, JPEG, JPEG2000, Lossless, LZW, RLE or Zip as alternate compression methods (some only allow b/w images). For details see here.

I was able to achieve great compression ratios for scanned/photographed documents (depending on the settings). Depending on the document source, you might want to reduce the color depth (-depth argument).

| improve this answer | |
  • 3
    For a scanned document where the text is what you are interested in rather then the images and preserving depth isn't an issue, jpeg compression is not a good idea because the artifacts tend to be extremely noticeable. If you use pdfimages input.pdf pages to extract pbm files, then you can do something like: for page in *.pbm; do convert $page -compress Group4 -type bilevel TIFF:- | convert - output.pdf. Any OCR will be lost so I usually then do pdfsandwich output.pdf, which seems to reduce file size even further. – Brian Z May 4 '15 at 11:57
  • 1
    @BrianZ sure jpeg compression isn't always the best choice, but for me it was the best approach for mixed type documents. I added some informations about other compression methods to the answer. – someonr May 6 '15 at 23:43
  • 2
    This method ultimately uses gs behind the scenes. – alfC Jun 12 '15 at 4:55
  • 2
    I had to use double dash for the options to run the command --density --quality --compress vs -density -quality -compress. – Rotareti Nov 10 '16 at 18:22
  • 1
    If image qaulity is not the highest concern (and you just want to get that dang email attachment small enough to be sent) one might add -resize 50% too, change percentage depending on how much DPI was used while scanning – chrki Jan 11 '17 at 0:45


I used a combination of the below ghostscript command and one from another thread.

gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dDownsampleColorImages=true \


| improve this answer | |
  • 4
  • Fantastic that one can tune the resolution with this command - this gave me better results than just using dPDFSETTINGS=\screen – exchange May 13 '19 at 10:04

Here is a script for rewriting scanned pdfs:


gs  -q -dNOPAUSE -dBATCH -dSAFER \
    -sDEVICE=pdfwrite \
    -dCompatibilityLevel=1.3 \
    -dPDFSETTINGS=/screen \
    -dEmbedAllFonts=true \
    -dSubsetFonts=true \
    -dColorImageDownsampleType=/Bicubic \
    -dColorImageResolution=72 \
    -dGrayImageDownsampleType=/Bicubic \
    -dGrayImageResolution=72 \
    -dMonoImageDownsampleType=/Bicubic \
    -dMonoImageResolution=72 \
    -sOutputFile=out.pdf \

You could customise it a bit to make it more reusable but if you only have one pdf, you could just replace $1 with your pdf filename and bung it in a terminal.

| improve this answer | |
  • 1
    Works a treat, thanks Oli. You've answered pretty much everything I've asked on here so far :-D – Rob Cowell Sep 1 '10 at 8:15
  • This is a good answer but in my case at least it takes a lot of time to convert a somewhat large (>10Mb) PDF file (more than a minute). – Gabriel Jun 12 '13 at 19:20
  • 1
    I'm not sure what happens, but a 30 MB PDF results a 68 MB file. Instead of reducing, it enlarges. Same output if using directly ps2pdf as stated in next answer. – Ed Villegas Jun 23 '13 at 18:08
  • 1
    @EdVillegas The only thing I can think of (to explain that sort of increase) is that the images are of a lower resolution than the ones being generated (72dpi). Or somehow embedding the fonts is sucking in all the fonts. – Oli Jun 25 '13 at 7:31
  • use pdfimages -list file.pdf to see the native images resolution. – vstepaniuk May 21 at 10:53

I usually use ps2pdf to do this (easier syntax), something like this:

ps2pdf -dPDFSETTINGS=/ebook BiggerPdf SmallerPDF

I use the following python script to reduce the size of all the pdf files in a dir in a production server (8.04). So it should work.


import os

for fich in os.listdir('.'):
        if fich[-3:]=="pdf":
                os.system("ps2pdf -dPDFSETTINGS=/ebook %s reduc/%s" % (fich,fich))
| improve this answer | |
  • Thanks for the alternative solution. I tried Oli's first and it gave me the result I needed, but I will keep this one for future reference too. – Rob Cowell Sep 1 '10 at 8:17
  • 1
    -dPDFSETTINGS=/printer option do 50% resize. ebook do 90% resize. – neouyghur Apr 13 '18 at 6:08
  1. I use LibreOffice Draw to open the pdf.
  2. I then "export as pdf"
  3. And set "jpeg compression quality" to 50% and "image resolution" to 150 dpi

This will have a good result.

| improve this answer | |
  • Worst possible solution to the problem! It totally messed my file up! – user783132 Jan 15 '18 at 16:31
  • For my this solutions is the best, it is only necessary to configure it depends on what one wants to do. Working for my with this settings "jpeg compression quality" to 83% and "image resolution" to 150 dpi – Indacochea Wachín Jun 3 at 14:39

Best for me was

convert -compress Zip -density 150x150 input.pdf output.pdf

Other ways:

#### gs

### pdf2ps && ps2pdf
pdf2ps input.pdf output.ps && ps2pdf output.ps output.pdf

### Webservice


| improve this answer | |
  • Great solution. Easy to remember and it brought my pdf from 32 to 3.5 MB without sensible loss in readability. – Immanuel Weihnachten Mar 17 '18 at 9:57
  • I liked the second way pdf2ps input.pdf temp.ps && ps2pdf14 temp.ps output.pdf && rm temp.ps – McPeppr Nov 6 '18 at 21:16

I strongly recommend pdfsizeopt.

It is much more efficient in terms of size reduction than any of the previous CLI and GUI software that I have tried (including convert, gs, pdftk, etc.) — although possibly slower with pngout activated —, and does not have some of their issues (no heavily pixelated/degraded images, no loss of metadata such as table of contents, etc.).

Now, if you need to attain a certain size whatever the consequences (inc. degrading images to a point of unreadability), it might not be the tool you need, but as an always-working go-to solution, to reduce unnecessary big sizes in PDFs without loosing in readability, information and acceptable image quality, I think it is the best option. (Note: I tend to use it after having first done a vectorization-OCR in Adobe Acrobat [the function used to be called "CleanScan"], which can have a dramatical size impact on some scanned text documents.)

I recommend the generic Unix install:

  1. Install all required dependencies:

  2. Download and install the executable:

    curl -L -o https://raw.githubusercontent.com/pts/pdfsizeopt/master/pdfsizeopt.single
    cp pdfsizeopt.single /usr/local/bin/pdfsizeopt


pdfsizeopt original.pdf [compressed.pdf]

Note for mac users finding this post (or Linuxbrew users): there is a Homebrew install formula:

brew install --HEAD pts/utils/pdfsizeopt
| improve this answer | |
  • 1
    what MARVELOUS GEM of a software! Thank you very much for reccomending this :-) – luca76 Nov 13 '19 at 13:39


| improve this answer | |
  • 1
    This is the single answer in this thread that solved my problem. I downplayed Simplescan, but it really was the answer for me, instead of fighting against Xsane in what seemed to be an endless agony. – versvs Aug 31 '15 at 16:03

Control the compression quality:

INPUT=$1; shift
OUTPUT=$1; shift

# Image Compression Quality
# Quality HSamples VSamples QFactor
# Minimum [2 1 1 2] [2 1 1 2] 2.40
# Low     [2 1 1 2] [2 1 1 2] 1.30
# Medium  [2 1 1 2] [2 1 1 2] 0.76
# High    [1 1 1 1] [1 1 1 1] 0.40
# Maximum [1 1 1 1] [1 1 1 1] 0.15 

${GS_BIN} -dBATCH -dSAFER -DNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=${OUTPUT} -c "<< /ColorImageDict << /QFactor ${QFACTOR} /Blend 1 /HSample [1 1 1 1] /VSample [1 1 1 1] >> >> setdistillerparams" -f ${INPUT}
| improve this answer | |
  • ...so both INPUT and OUTPUT are the same argument? You might want to add usage guidelines. – mikewhatever Apr 2 '16 at 11:46
  • 2
    Note the shift. First parameter is input file, second is the output file and rest of the parameters will be passed to gs as is. – Mikko Rantalainen May 13 '16 at 12:53
  • I think you want /HSamples and /VSamples, not /HSample and /VSample. See e.g. ps2pdf docs or the PostScript language reference manual. Also perhaps worth noting that the allowed QFactor range is 0 to 1,000,000 and lower values produce higher quality. – Pont Aug 2 '17 at 8:31



convert -compress Zip input.pdf output.pdf
| improve this answer | |
  • I guess this is what you meant by "a little fuzzy", but just to clarify, convert -compress Zip appeared to rasterise all vectors. – Sparhawk Feb 22 '15 at 3:39

In the end I wrote my own bash script to solve this, it uses mogrify, convert and gs to extract pdf pages as png, resize them, convert them to 1-bit bmp and then rebuild them as pdf. File size reduction can be over 90%. Available at http://www.timedicer.co.uk/programs/help/pdf-compress.sh.php.

| improve this answer | |

I was facing the same problem, and was glad to find this thread. Specifically I had a pdf generated from scanned images, and needed to reduce its byte size by a factor of 6.

Unfortunately, none of the solutions above worked :(. Then I realized that somewhere in the scanner->jpeg->pdf process the size of the page had gotten bloated by a factor of aprx 4. The documents I scanned were all Letter sized, but the pdf had size of

identify -verbose doc_orig.pdf | grep "Print size"
 Print size: 35.4167x48.7222

I got the desired results finally with a "convert" command that did both resizing as well as compression steps in one:

convert -density 135x135 -quality 70 -compress jpeg -resize 22.588% doc_orig.pdf doc_lowres.pdf

Note that doc_orig had density of 72x72 dpi.

| improve this answer | |

If converting to djvu would also be ok and if no colors are involved, you could try the following:

Convert the pdf to jpg files using pdfimages -j

If you get pbm files instead, you should do the intermediate step:

for FILENAME in $(ls *.pbm); do convert $FILENAME ${FILENAME%.*}.jpg ;done

The convert command is from the imagemagick package.

Then use scantailor to make tif's out of it.

In a last step you go to scantailors out direcory (where the tif's are located) and apply djvubind to that directory.

This should reduce the filesize drastically without big quality loss of the text. If you want finer control over the ocr-backend, you may try djvubind --no-ocr and use ocrodjvu to add the ocr layer afterwards.

If you have color's in your document things get a bit more complicated. Instead of djvubind you could use didjvu and in scantailor you have to change to mixed mode and select sometimes color-images manually.

| improve this answer | |

load image or even pdf file into inkscape.



| improve this answer | |

For me the gs screen option was too bad, and the ebook one too big.

My original document contained text as colour and black and white images (depending on the page).

The best solution I did come up has been:

gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dDownsampleColorImages=true -dDownsampleGrayImages=true -dDownsampleMonoImages=true -dColorImageResolution=130 -dGrayImageResolution=130 -dMonoImageResolution=130 -r130 -dNOPAUSE  -dBATCH -sOutputFile=output_lr.pdf input.pdf

Note that the compression level is not linear.. if I was specifying 135 it didn't compressed, I did find 130 to be (in my case) the maximum resolution that achieves a compression.

| improve this answer | |

Super simple PDF compress tool: GitHub page.

Installation on Ubuntu:

sudo add-apt-repository ppa:jfswitz/released

sudo apt-get update

sudo apt-get install pdf-compressor

It uses ghostscript.

| improve this answer | |

You can try this :

$ time pdftk myFile.pdf output myFile__SMALLER.pdf compress
GC Warning: Repeated allocation of very large block (appr. size 16764928):
    May lead to memory leak and poor performance.
GC Warning: Repeated allocation of very large block (appr. size 8384512):
    May lead to memory leak and poor performance.
GC Warning: Repeated allocation of very large block (appr. size 11837440):
    May lead to memory leak and poor performance.
    May lead to memory leak and poor performance.
GC Warning: Repeated allocation of very large block (appr. size 33525760):
    May lead to memory leak and poor performance.
GC Warning: Repeated allocation of very large block (appr. size 7254016):
    May lead to memory leak and poor performance.
GC Warning: Repeated allocation of very large block (appr. size 34041856):
    May lead to memory leak and poor performance.
    May lead to memory leak and poor performance.

real    0m23.677s
user    0m23.142s
sys     0m0.540s
$ du myFile*.pdf
108M    myFile.pdf
74M     myFile__SMALLER.pdf

It is faster than gs but compresses upto 30% in this case for a 107.5MiB input file.

| improve this answer | |

I used below commands but it didnt compress my pdf file substantially. Some times some of the portion was blackened after compression.

  1. gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/ebook -dNOPAUSE -dQUIET -dBATCH -sOutputFile=output.pdf $INPUTFILE

  2. "ps2pdf -dPDFSETTINGS=/ebook %s %s" % (input_file_path, out_file_path)

After too much wandering over the web I just couldn't find the right compression library. I came across pdfcompressor.com. This is just awesome website. It compresses the pdf by 95% ( 15Mb of files). So I used selenium and Tor to automate the compression. Checkout my Github Repository. [GITHUB] (https://github.com/gugli28/PdfCompressor)

| improve this answer | |
