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
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
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
Here’s a bitcookie 8635 for you for your great tip.