We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Compress PDF File Size in C#

Hi support
i am struggling to compress a pdf.
i am using various options such as PdfPageEditor.Optimize(), .OptimizeResources(), .RemoveUnusedObjects = True, .UnembedFonts = True etc.
however, if i go to https://pdfcompressor.com/ and upload my pdf, they manage a 75% reduction in size.06S18E33.PDF (1.4 MB)
so the attached pdf goes from 1.4MB to 300KB.
is there anything in the toolkit to allow me to achieve the same?


We used the below code snippet to compress your PDF document and achieved 668KB file:

var oo = new Aspose.Pdf.Optimization.OptimizationOptions();
oo.ImageCompressionOptions.ImageQuality = 20;
oo.ImageCompressionOptions.MaxResolution = 144;
oo.ImageCompressionOptions.ResizeImages = true;
oo.ImageCompressionOptions.CompressImages = true;
oo.ImageCompressionOptions.Version = Aspose.Pdf.Optimization.ImageCompressionVersion.Fast;
oo.RemoveUnusedObjects = true;
oo.RemoveUnusedStreams = true;
oo.LinkDuplcateStreams = true;
oo.SubsetFonts = true;
oo.AllowReusePageContent = true;
oo.UnembedFonts = true;

using (Document document = new Document(dataDir + "06S18E33.pdf"))
 document.OptimizeSize = true;
 document.Save(dataDir + "output" + DateTime.Now.Millisecond + ".pdf");

output198.pdf (668.0 KB)

Would you please check the attached file and let us know in case it satisfies your requirements?

Hi Asad
the routine works well for smaller pdfs, however, it gives an error (Not supported image type) with a larger pdf, i will try to attach. (failed, file is 14MB, upload limit is 5)
all pdfs were created using the same system, so the error message is odd.

Hi Asad,

i just updated my aspose version, not a big update, but it is now working.
fingers crossed, 600,000 pdfs to go.
thanks for the code.


Please take your time to evaluate the API and feel free to let us know in case you face any issues.