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.
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.
Use the following ghostscript command:
Summary of
-dPDFSETTINGS
:-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 fileReference: https://www.ghostscript.com/doc/current/VectorDevices.htm#PSPDF_IN:
The exact settings for each of these, including their DPI values, are shown in the dozens of options in this table: https://www.ghostscript.com/doc/current/VectorDevices.htm#distillerparams.
My favorite way to do this is to convert the PDF to PostScript and back. It does not always work, though, but when it works the results are nice:
This also directly works on PDFs, as suggested in the comments.
Some users also report more success when using the ebook settings as follows:
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.
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:
Adjust the parameters to your needs
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).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 below ghostscript command and one from another thread.
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.
Here is a script for rewriting scanned pdfs:
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.This will have a good result.
I usually use ps2pdf to do this (easier syntax), something like this:
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.
Best for me was
Other ways:
regards
Referencing this answer and this answer, and after trying a bunch of the answers here, and doing a bunch of research and experimenting, I've come up with the following. Note that I've removed the
-dCompatibilityLevel=1.4
part of the command used in some other answers here (including the most-upvoted answer) because this table indicates that1.5
or1.7
are automatically used for this setting today (27 Dec. 2020), and there's no need to override those values.Use Ghostscript (
gs
) to compressinput.pdf
intooutput.pdf
3 Main levels of compression:
Note: you may also add
-dQUIET
to suppress all output to stdout. See: https://www.ghostscript.com/doc/current/Use.htm.You can also add
time
in front of the command to see how long it takes (this works with any Linux command). Sample output:If you add
-dQUIET
to the command, none of the Ghostscript output is shown, and you get this (when usingtime
in front):You can also use
ps2pdf
, which is a wrapper aroundgs
, and produces very similar, but not exactly identical, results. I prefer to just usegs
directly, as shown above, however.PDF Compression Tests
Testing the
gs
commands above on output from mypdf2searchablepdf
script here, I see the following:Ghostscript (
gs
) Documentation:For all
-d
("d
efine")PDFSETTINGS
available, see here: https://www.ghostscript.com/doc/current/VectorDevices.htm#PSPDF_IN. I have quoted that section below, except that I've added the DPI values for each setting in bold, as taken from this table here. You can refer to that table to see the dozens of lower-level settings chosen bygs
for eachPDFSETTINGS
option.You can also see definitions for various options on this page: https://www.ghostscript.com/doc/current/Use.htm: