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

Free Support Forum - aspose.com

Shrink Large PDF

Greetings,


I have a very large PDF document (30Mb), is there a way to compress the images and text in this file? The aspose.word library allows you to select the imageCompression on pdf save, does something like that exist in the aspose.pdf library.

I have tried the OptimizeResources method but the resulting file ends up slightly bigger.

Document doc = new Document(“test.pdf”);
doc.OptimizeResources();
doc.Save(“Optimized.pdf”);

Cheers,

IT

Hi there,


Thanks for your inquiry. Please check following code to compress images within PDF document, without extracting images. Later you can try to optimize the document. Hopefully it will serve the purpose. If issue persist then can you please share your sample document via some free file sharing services e.g. Dropbox, Skydrive etc? So we will test the scenario at our end and will provide you more information accordingly.

Document pdfDocument = new Aspose.Pdf.Document(“input.pdf”);

foreach (Page page in pdfDocument.Pages)
{
int idx = 1;
foreach (Aspose.Pdf.XImage image in page.Resources.Images)
{
using (var imageStream = new MemoryStream())
{
image.Save(imageStream, ImageFormat.Png);
imageStream.Seek(0, SeekOrigin.Begin);
page.Resources.Images.Replace(idx, imageStream);
}
idx = idx + 1;
}

}
pdfDocument.Save(“output.pdf”);

Please feel free to contact us for any further assistance.

Best Regards,

Hi Luke,


Thanks for using our products.

Can you please share the source PDF file so that we can test the scenario at our end. The problem might be occurring due to complexity and structure of input document. We are sorry for this inconvenience.