Take the 2-minute tour ×

I'm looking for a library or command-line program that can compress PDFs.

Compression speed and file size are very important.

The PDFs are full of very large print-quality images.

Adobe Acrobat does high-quality, fast compression but does not allow "reduced size pdfs" to be saved through a programmatic interface.

Ghostscript does high-quality compression be takes way too long (minutes).

share|improve this question
This is the best solution I've found so far: gswin64c.exe -dQUIET -dBATCH -dNOPAUSE -dNOGC -dPDFSETTINGS=/screen -sDEVICE=pdfwrite -sOutputFile=compressed.pdf input.pdf. It takes about 20 seconds to convert a 126 MB file to 3.2 MB. –  user1359680 Oct 19 '12 at 14:35
Thanks user1359680. That is simple and great, only in my case a gswin32c.exe was already found on my system. I will wrap that into a .cmd one-line script and place into my SendTo folder for easy right-click applying. –  Marcos Nov 19 '12 at 11:51
Update: I went with Neevia CompressPDF for $99. It doesn't compress the fonts or mess with the text. Ghostscript sometimes removes letters from the searchable text layer. Another solution is to convert the PDFs to HTML5 using IDR Solutions' jpdf2html.jar but it's expensive for a license ($2500) –  user1359680 Nov 19 '12 at 15:44

2 Answers 2

If a commercial library is an option, you could give Amyuni PDF Creator a try. There is .net version (C#/VB.Net etc) and an ActiveX version (for C++/Delphi/VB/PHP etc).

You can iterate through all the objects of each page, pick those who are images, and reduce their size. You have several possibilities there:

  1. Setting a lower compression rate.
  2. Down-sampling (extracting the image, re-sizing it to a lower resolution, and putting it back in your file)
  3. Combining the previous two.

Here is how the code would look like for the first option, in C#, using Amyuni PDF Creator .Net:

//open a pdf document
IacPage page1 = document.GetPage (1);
Amyuni.PDFCreator.IacAttribute attribute = page1.AttributeByName ("Objects");
// listobj is an array list of graphic objects
System.Collections.ArrayList listobj = (System.Collections.ArrayList) attribute.Value;
foreach ( object pdfObj in listobj )
    if ((IacObjectType)pdfObj.AttributeByName("ObjectType").Value == IacObjectType.acObjectTypePicture)
        if ((IacImageCompressionConstants)pdfObj.AttributeByName("Compression").Value == IacImageCompressionConstants.acCompressionJPegMedium)
            pdfObj.AttributeByName("Compression").Value = IacImageCompressionConstants.acCompressionJPegLow;

        if ((IacImageCompressionConstants)pdfObj.AttributeByName("Compression").Value == IacImageCompressionConstants.acCompressionJPegHigh)
            pdfObj.AttributeByName("Compression").Value = IacImageCompressionConstants.acCompressionJPegMedium;
        // (...)

usual disclaimer applies

share|improve this answer

You might want to try Docotic.Pdf library for your task.

Here is a code that scales all images that have width or height greater or equal to 256. Scaled images are then encoded using JPEG compression with quality set to 65.

public static void RecompressToJpeg(string path, string outputPath)
    using (PdfDocument doc = new PdfDocument(path))
        foreach (PdfImage image in doc.Images)
            // not good candidates for recompression
                image.Scale(0.5, PdfImageCompression.Jpeg, 65);


You could also just recompress images without changing their sizes using one of the RecompressWithJpeg methods (or one of other RecompressXXX methods).

And images can be resized to specified width and height using one of the ResizeTo methods. Please note that you will need to take aspect ratio into account in the latter case.

Disclaimer: I work for the vendor of the library.

share|improve this answer

Your Answer


