Free Support Forum - aspose.com

Pdf.Document.OptimizeResources not working after saving Word document as Pdf

I am attempting to split 1 pdf document with x pages into x pdf documents with 1 page. When these pdf documents contain images, I am finding that the resulting pages contain all of the embedded resources from the original document. According to this post (<a href="https://forum.aspose.com/t/97576) OptimizeResources is supposed to strip all unused resources from a Pdf, however, I am not getting these results.


Words.Document wordDoc = new Words.Document("ImageAndText.docx"); MemoryStream wholePdfStream = new MemoryStream(); wordDoc.Save(wholePdfStream, Words.SaveFormat.Pdf); wholePdfStream.Seek(0, SeekOrigin.Begin); Pdf.Document wholePdf = new Pdf.Document(wholePdfStream); foreach (Pdf.Page page in wholePdf.Pages) { Pdf.Document singlePagePdf = new Pdf.Document(); singlePagePdf.Pages.Add(page); singlePagePdf.OptimizeResources(); singlePagePdf.Save(String.Format(@"pages\{0}.pdf", page.Number)); }

The result of this code is:

FileName FileSize
1.pdf 1370kb
2.pdf 1380kb
3.pdf 1380kb
4.pdf 1370kb

As you can see, the pages with only text are actually larger as they are storing the images and text.
When I use Microsoft Word to save the document as Pdf first and then run the following code:

Pdf.Document wholePdf = new Pdf.Document("ImageAndText.pdf"); foreach (Pdf.Page page in wholePdf.Pages) { Pdf.Document singlePagePdf = new Pdf.Document(); singlePagePdf.Pages.Add(page); singlePagePdf.OptimizeResources(); singlePagePdf.Save(String.Format(@"pages\{0}.pdf", page.Number)); }

The result of this code is:

FileName FileSize
1.pdf 172kb
2.pdf 81kb
3.pdf 81kb
4.pdf 193kb

This makes me thing that there is something wrong with the way that Aspose.Words is saving the document when saving as a Pdf.
I have attached both the original Word file and the pdf file I created using Microsoft Word.

After doing some more testing, I found that saving the pages from Aspose.Words individually resulted in much smaller page sizes.


Words.Document wordDoc = new Words.Document(@"input\ImageAndText.docx"); for (int i = 0; i < wordDoc.PageCount; i++) { wordDoc.Save(String.Format(@"pages\{0}.pdf", i), new Words.Saving.PdfSaveOptions { PageCount = 1, PageIndex = i }); }

This gives me the following results:

FileName FileSize
1.pdf 608kb
2.pdf 12kb
3.pdf 12kb
4.pdf 762kb

Hi John,


Thanks for your inquiry.

While using the latest versions of Aspose.Words for .NET (13.2.0) and Aspose.Pdf for .NET (7.8.0), I was unable to reproduce this issue on my side. I would suggest you please upgrade to the latest versions of Aspose.Words and Aspose.Pdf. You can download them from the following links:

http://www.aspose.com/community/files/51/.net-components/aspose.words-for-.net/default.aspx
http://www.aspose.com/community/files/51/.net-components/aspose.pdf-for-.net/default.aspx

I hope, this helps.

Best regards,

Sorry about that. I was linking to an older version of the dll.

Hi John,


Thanks for your feedback. It is perfect that the latest versions of Aspose products resolve the problem. Please let us know any time you have any further queries. We are always glad to help you.

Best regards,