Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Any suggestions for shrinking a PDF file?

Tags:

.net

pdf

filesize

We've got a .net 2.0 web system that dynamically builds pdf files. Some of these files can get pretty large - 12MB+. While processing time isn't a factor, really, the size of the files to be downloaded is in some cases.

For the moment, let's assume that our B-grade pdf library is already making the smallest files that it knows how. (Although, if anyone has any suggestions on that front, do see this related question.)

However, taking the 12MB file in question and sending it though the Acrobat distiller results in a roughly 700K file, with no appreciable loss in print quality.

I'd love to have some kind of post-processor that does even a third of that. Does anyone have any controls they know about that'll do something like this?

The cheaper the better, for this project, but we're not adverse to throwing a few bucks down.

(Some preemptive comments: naturally, rewriting the existing PDF generation code with a new tool is off the table at the moment. Also, while Distiller seems to have an API, calling that on a webserver doesn't seem like the most efficient course - and Distiller is a little pricey. Finally, we'd just as well not wrap the pdfs in a zip file or some such, since that may baffle the clients somewhat. No, really.)

Thanks!

like image 345
Electrons_Ahoy Avatar asked Mar 04 '09 21:03

Electrons_Ahoy


2 Answers

Use Ghostscript, which is also available for the 32bit and 64bit Windows platforms. It recognises all Adobe Distiller parameters[1] and honors most of them. On top of that, you can inject PostScript programs into the conversion process. I use it for a year now in a pre-print production environment on image-heavy PDFs. If the parameters are set correct, the file-size can go from 40MB down to 800kB with no visible loss of quality. I found it to be quite fast, in fact the documentation states that it may be faster than Adobe Distiller.

And it is free (as in beer as well as in speech).

[1] See distparm.pdf in the help folder of Distiller or look here.

How you use it

You call it from the command line with all your wanted parameters, input and output-files and you're done.

Quick example:

gs -dBATCH -dNOPAUSE -sDEVICE=pdfwrite\
   -dCompatibilityLevel=1.3 -dEncodeColorImages=true\
   -sOutputFile=output.pdf input.pdf

Some valuable resources:

  • Ghostscript PDF writer tips
  • Postscript-to-PDF converter documentation
like image 135
pi. Avatar answered Oct 19 '22 06:10

pi.


PDF's usually use JBIG/JBIG2/JPEG2000 compression. Cvision's PDFCompressor is the best for compressing PDF's.

like image 23
StingyJack Avatar answered Oct 19 '22 06:10

StingyJack