UPDATED (9/7/11): The package is not pdftk, but Ghostscript, and it’s easily installable through homebrew on a mac.
Ok, so I don’t know why this works, but it does and I haven’t seen any decrease in quality. I suspect converting from PDF to PS and back just optimizes the PDF.
Requirements
- pdftk for linux
The Process
- Convert your PDF to PS (this creates a large file
- Convert the new PS back to a PDF
pdf2ps large.pdf very_large.ps
ps2pdf very_large.ps small.pdf
Results
large.pdf : 6.3MB
very_large.ps : 53.4MB
small.pdf : 2.4MB
Looks like pretty good compression to me.
If anyone knows why this works so well, please let me know.
I guess there is some quality loss during the process. Losing lines and curves just having bitmaps …
pdftk is also able to uncompress and compress a pdf (see those options for the ‘pdftk’ binary) which should simply uncompress and recompress the data within the pdf to produce a smaller pdf — but not as small as the improvement you got.
This method not always work, in my case the resulted PDF is bigger.
Very good!
thanks
Pingback: Compressione di un pdf con minima perdita di qualità « Il blog di Andrea Lazzarotto
I don’t know what happends during the process but it helps me a lot 🙂 Great!
Thanks
it blanked the top edges of all pages…
Thank you sooooo very very much for those instructions! I had this pdf file that was, believe it or not, 747 Mb in size. After using your instructions, I got myself a file that was ONLY 11 Mb in size without any loss in quality to the file! Thank you again!
handy 6MB->227KB
Its one and a half years since your post…but still helping people 😉
Thanks.
Thanks!
7.2 MB -> 360 MB -> 14.3 MB 😦
I have the same problem.
10.9 MB to 486 MB to 56 MB!
I suggest you use this method:
ps2pdf -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/screen -dNOPAUSE -dQUIET -dBATCH -sOutputFile=out.pdf original.pdf
Hmm…
with this howto I got 4.9 MB from 1.4 MB in size! Something went wrong!
Install ghostscript and:
gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/screen -dNOPAUSE -dQUIET -dBATCH -sOutputFile=output.pdf input.pdf
LaPeGa: Thanks! Exactly what I was looking for!
Your solution compress images greatly, reducing the PDF file size considerably. It’s a lossy compression (loose some information) in the images. The text is still selectable after compression. Exactly what someone need when trying to send a large PDF by email.
Nice tip.
One thing though, I don’t believe pdftk is required here. In fact, you are not even using it. The commands pdf2ps and ps2pdf are part of ghostscript.
Too bad it didn’t help me, my 42 mb file went up to 7.9 gb and down to 1.4 gb 😦
It doesn’t work in my case, which generated a bigger file…
that worked great! Best solution yet! Crushed my 27 mb down to 6.8mb
Pingback: hx4
Great! Thanks
It’s just incredible. Has one PDF made of 800×600 photographs of a document = 75 Mb. After your treatment = 23.1 Mb.
I thought if I looped the process it were going to be like 10 Mb. It was not. It was = 23.1 Mb. So, no fractal allowed!
Thanks!
Still a great tip! Thanks.
(90MB -> 15MB)
THANK YOU VERY MUCH!
SOURCE was 645 MB ==> RESULT is 7,5 MB
You can also use ImageMagick’s convert or mogrify tools to downsample a PDF. e.g; convert foo.pdf -colors 2 -density 150×150 bar.pdf might turn a 5.5 Mb, 300dpi grayscale PDF into a 457kb 150dpi B&W PDF. However you get more readable results at the expense of larger output (1.4Mb) if converting to B&W with ps2pdf foo.pdf | pdf2ps – bar.pdf and mogrifying the results.
Note that this is for image-based PDFs e.g; scanned pages
pdf2ps and ps2pdf are not a part of pdftk
Interesting. It is working well.
Thanks for this tip.
From 220Mb pdf to 1,9 Gb ps to a 72Mb PDF!
Thank you!
This worked well for me here. I had a 3,3MB PDF that contained a few scanned pages beside text. This trick reduced the size to 1,4MB instead!
Thanks for sharing, even if it does not work for every document, it is still worth a try!
gs -dNOPAUSE -sDEVICE=pdfwrite -r150 -sOUTPUTFILE=merged.pdf -dBATCH *.pdf
>>>( -r150 )<<< set output file to 150dpi
-r100 set 100dpi etc etc…
my 2 cents
Thanks, one PDF went from 258MB to 8MB. In case you are using Python 2.7, here’s a little script that provides a very basic GUI. Creates two folders, one for the PS file, one for the compressed PDF. Hope the indentations display properly…
+++++++++++++++++++++++++++++++++++++
import os, subprocess, Tkinter, tkFileDialog, tkSimpleDialog
from Tkinter import *
root = Tk()
root.title(“PDF Compressor”)
def compressPdf():
volumeDirectory = str(tkFileDialog.askdirectory(title=”Select Volume”))
pathName, directoryName = os.path.split(volumeDirectory)
directoryNameNew = directoryName + ‘_compressed’
directoryPathNew = os.path.join(pathName, directoryNameNew)
psDirectoryName = directoryName + ‘_ps’
psDirectoryPath = os.path.join(pathName, psDirectoryName)
if os.path.exists(directoryPathNew):
pass
else:
os.makedirs(directoryPathNew)
if os.path.exists(psDirectoryPath):
pass
else:
os.makedirs(psDirectoryPath)
pdfFiles = os.listdir(volumeDirectory)
for pdfFile in pdfFiles:
pdfFileName, extension = pdfFile.split(“.”)
psFileName = pdfFileName + ‘.ps’
pdfOldPath = os.path.join(pathName, directoryName, pdfFile)
psPath = os.path.join(psDirectoryPath, psFileName)
pdfNewPath = os.path.join(directoryPathNew, pdfFile)
subprocess.call([“pdf2ps”, pdfOldPath, psPath])
subprocess.call([“ps2pdf”, psPath, pdfNewPath])
print pdfNewPath
print ‘+++++++++++++++++++’
print ‘Done!’
def close():
root.destroy()
menu = Menu(root)
root.config(menu=menu)
## File Menu
filemenu = Menu(menu)
menu.add_cascade(label=”File”, menu=filemenu)
filemenu.add_command(label=”Exit”, command=close)
## Process Menu
processmenu = Menu(menu)
menu.add_cascade(label=”Process Data”, menu=processmenu)
processmenu.add_command(label=”Compress PDFs”, command=compressPdf)
mainloop()
Cool trick.
I just tried it with poor results – The output was 10x bigger than the input. But my ubuntu box has “pdf2ps” & “pdftops”. Using the latter instead of the former gave good results.
I have no idea why this works, but it’s a cool trick. Thanks!
Here’s another thing that shrinks a PDF where other tools fail… At least it worked with the file that lead me to this page 😉
gs -dNOPAUSE -dBATCH -dSAFER -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -sOutputFile=out-file.pdf in-file.pdf
YMMV.
This should work, but on some files it doesn’t… Which lead me to this page 😉
pdftk in-file.pdf output out-file.pdf compress
almost 4 years from your post and still useful.
pdftops & ps2pdf: 20mb -> 133mb -> 1.5mb.
simple and effective, thank you 🙂
I’m curious how often I can use this on one file….
Let me know what you find…
Pingback: Reducing PDF file size « Unforgettable Virtual Park
28MB -> 14MB
Nice!
322 MB to 2.2 GB to 177 MB, thumbs up!!
Although, I can say that there is a loss of quality.
it worked great for me from a 85mb to 182mb and then to a final 5.3! thank you.
Very helpful and simple…thank you
Reblogged this on baichuns and commented:
This work for me! thanks
this works for me! thanks
For my pdf with many images
pdf2ps & ps2pdf
525MB -> 1.7GB -> 335MB
Adobe acrobat pro reduced size saving
525MB -> 107MB
convert foo.pdf -colors 2 -density 150×150 bar.pdf
525MB -> 57MB (but none of the text is legible)
convert foo.pdf -density 175×175 bar.pdf
525MB -> 67MB (but none of the text is legible)
convert foo.pdf -density 225×225 bar.pdf
525MB -> 67MB (but none of the text is legible – no different than above)
Unfortunately will have to stick w/ adobe 😦
Thanks for the tips though! Seems to be best for more text than images pdfs
In my case this didn’t worked neither using pdf2ps nor pdftops. The pdf I am trying to compress is a scanned document. Thanks if anyone has some interesting comment about it.
7 years later, still useful.
Cheers mate!
This works like a charm. Thank you.
I guess the ghostscript solution is better than the pdf2ps and back ps2pdf because there the actual text does not get lost
Reblogged this on John Athanasiou and commented:
This is something I had no idea about. It’s a bit messy (links inside pdf are broken since it’s exported to another file) but fast and simple way to decrease a pdf’s size by ~50%
You will lose jpeg image quality. See
better to use
“`
gs -sDEVICE=pdfwrite -sOutputFile=output.pdf -dAutoFilterColorImages=false -c “<< /ColorImageDict <> >> setdistillerparams” -f input.pdf
“`
to preserve acceptable image quality.
See for acceptable ColorImageDict values.
This is brilliant. Added it to my IT Notes and gave you credit. Thanks.
Very useful, worked for me. Thanks!!!
4MB -> 600K
Otbained from PDF 892,2 kb → PS 13,4 Mb → PDF 456,5 kb but the embedded text in the original PDF had disappeared. (I had an image of a text, plus the text embedded. The result is pure image of the text, with nothing to copy as text and paste.)
Thanks!!!
10 years after… It works! 🙂
Thanks!
Thank you! Works better than online PDF shrinkers.
Thanks for keeping this online all this time too.