Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a 72.9MB PDF file that I need to shrink into under 500KB.

The file was a JPEG image that I had scanned, and then converted to pdf.

share|improve this question
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
convert it to DjVu, instead trying to reduce to impossible sized PDF (according source) – zetah Mar 16 '12 at 17:22
the file was a jpeg image that I had scanned, and then converted to pdf. – tamimym Mar 16 '12 at 19:53
It only seems to help filesize a little bit, but pdfopt has a simple syntax and improves loading and page-turning speed in the iPad era. :-) – Ari B. Friedman May 31 '12 at 0:53
PDF to PS is not effective in scanned PDF file, I try to convert 56 MB pdf into ps file but ps file convert into 1.3 GB and again ps2pdf is converted in 45 MB file – user124118 Jan 18 '13 at 5:32

14 Answers 14

up vote 57 down vote accepted

aking1012 is right. With more information regarding possible embedded images, hyperlinks etc.. it would be much more easier to answer this question!

Here are a couple of script and command-line solutions. Use as you see fit.

share|improve this answer
I should point out that if you're trying to downsize a >10MB PDF file to under 500KB, you'll be sacrificing a lot of content, because its strongly unlikely you'll be able to get that PDF down to the size you want... – Thomas Ward Mar 16 '12 at 17:31
Thank you very much for your suggestions, the ghostscript shell worked wonders and shrank it down to 460KB :) – tamimym Mar 16 '12 at 19:56
You are very welcome tamimym, and i am glad, that one of the suggestions fitted your needs!! (: – v2r Mar 16 '12 at 20:55
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
The first link lacks objection, I think. – vmassuchetto Aug 22 '15 at 23:00

Use the following ghostscript command:

gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/screen -dNOPAUSE -dQUIET -dBATCH -sOutputFile=output.pdf input.pdf

If the -dPDFSETTINGS=/screen setting is too low quality to suit your needs, replace it with -dPDFSETTINGS=/ebook for better quality, but slightly larger pdfs. Delete the setting altogether for the high quality default, which you can also explicitly call for with -dPDFSETTINGS=/prepress.

share|improve this answer
One can also make a Nautilus script to access this function for every file. – Sina May 7 '13 at 15:51
This should be the accepted answer. ghostscript is the PDF, XPS and PS implementation for unices and can do basically everything delivering best quality... – dom0 Oct 2 '13 at 17:27
@Sina: There is actually a Nautilus Script with a simple Zenity-based GUI that utilizes this gs command with all its quality-level options: – Sadi Oct 25 '13 at 11:47
This is the right answer for this question (compressing a pdf that is mostly bitmap data). I found that the screen setting was too low quality for me, but ebook worked well, cutting a 33Mb scan-based PDF down to 3.6Mb, and keeping it very readable. Other options for the -dPDFSETTINGS option are listed here:, and it might be a good idea to include them in this answer. – naught101 Dec 2 '14 at 1:13
gs available configuration parameters: – Antonios Hadjigeorgalis Dec 11 '14 at 23:41

My favorite way to do this is to convert the pdf to ps and back. It does not always work, though, but when it works the results are nice:

pdf2ps input.pdf
ps2pdf output.pdf

Good luck

share|improve this answer
This is a very simple and effective way to do it. I was surprised to see how much this method compressed the files. Thanks you! – Gabriel Apr 8 '13 at 12:59
Despite the fact that this one approach became my favorite solution to compress pdf files, it breaks up url links the document may have (which does not happen with @Michael D's approach). Apart from that, awesomeness is all I can think of running this snippet! (: – Rubens Dec 6 '13 at 11:01
@Rubens Ah. Did not know about the fact that it breaks the url links. Thanks for adding that. – don.joey Dec 6 '13 at 12:19
This bypasses password protection...just sayin' – jojo Jan 6 '15 at 20:28
Great solution! In contrast to printing to a postscript file in Evince, the quality didn't noticeably change. – balu Jan 28 at 7:45

If you have a pdf with scanned images, you can use convert 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).

share|improve this answer
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
@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
This method ultimately uses gs behind the scenes. – alfC Jun 12 '15 at 4:55

I needed to downsize a pdf that contained full color scans of a document. Each of my pages was a full color image as far as the file was concerned. They were images of pages containing text and images, but they were created by scanning to an image.

I used a combination of the above Ghostscript command and one from another thread.

gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dDownsampleColorImages=true /
-dColorImageResolution=150 -dNOPAUSE  -dBATCH -sOutputFile=output.pdf input.pdf

This reduced the image resolution to 150dpi, cutting my file size in half. Looking at the document, there was almost no noticeable loss of image quality. The text is still perfectly readable on my 2012 Nexus7

share|improve this answer
+1 for down sampling images but keeping text as vectors. Made a huge difference in side without making my text pixelated. – Jason O'Neil Dec 8 '14 at 8:34
What is the forward slash in that command? The command only worked if I removed the slash. – chrisdembia Feb 23 at 18:38
The forward slash is needed when a command is split across multiple lines. – Abid H. Mujtaba Feb 24 at 16:43

I just encountered this problem myself. If using simple scan, select text mode for low resolution scans and you won't need to worry about the command line stuff. Just saying.

share|improve this answer
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

Since this link was first for me when I searched in Google, I thought I'd add one more possibility. None of the above solutions was working for me on a pdf exported from Inkscape (15 mb), but I was at last able to shrink it down to 1 mb by opening it in GIMP, and exporting as pdf again.

Another option that came close (but text was a little fuzzy) was ImageMagick's convert utility:

convert -compress Zip input.pdf output.pdf
share|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

Vectorizing all fonts will help. Don't embed fonts into the file.

Use small image resolution: most of the time you really dont need HD pictures. Be careful with image software like Gimp, it can make very large compressed file (beware how you compress it). I don't like proprietary softwares but some Adobe Photoshop compression tools are better than Gimp one.

More: do you need to put the image into a PDF file?

It's very simple, but more than image resolution, you can simply change the document size...

@Lord of Time is right: switch from 72Mo to 500Ko will be hard without changing something radically.

share|improve this answer

load image or even pdf file into inkscape.

From inkscape: Save in vector format (as the native .svg).

Import vector files into scribus, edit layout and export/save as .pdf from there

share|improve this answer

shrinkpdf cut down the pdf size in my case from 5.6 MB to 1.1 MB choosing to go with 100 DPI. The original scanned document was in 200 DPI

share|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.

share|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.

share|improve this answer

Best for me was

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

Other ways:

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

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

### Webservice


share|improve this answer
  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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.