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

Free Support Forum - aspose.com

Composite PDF file being split with OptimizeResources() resulting in corrupt pages

When using the Aspose .Net PDF library to split some composite PDF files, a call to OptimizeResources() results in some corrupt split PDF pages; which fail to load in Adobe Acrobat (PitStop) viewer giving an error:

“Could not get color space from shading pattern.”

A call to pdfDocument.OptimizeResources() was

the cause of this.

PDF files in question have axial smooth shades and DeviceN color space on the pages that happen to have issues when split with OptimizeResources().

Everything splits fine if the call to OptimizeResources were removed. But we need to use OptimizeResources for some of the files that are bloated and result in individual component page files with the same file size as the size of the composite PDF.

Code snippet explaining how it was being used is attached.

Would this be a bug in the Aspose PDF library OptimizeResources method cleaning up (or optimizing) too much?

Hi Gurjeet,

Thanks for contacting support.

I have tested the scenario using one of my sample PDF files where I have used the same code snippet and I am unable to notice any issue while viewing the resultant PDF files. Can you please share your sample PDF document, so that we can test the scenario in our environment. We are sorry for this inconvenience.

Hi Gurjeet,

Thanks for sharing the resource file.

I have tested the scenario using Aspose.Pdf for .NET 11.3.0 in VisualStudio 2010 project with .NET Framework 4.0 running over Windows 7 and I am unable to notice any issue. For your reference, I have also attached the output generate over my end.

Please note that I have marked this forum thread as private so that the contents shared in this thread are only accessible to Aspose staff.


pdfDocument = new Aspose.Pdf.Document(“c:/pdftest/Test_OptRemoveUnusedStreams.pdf”);<o:p></o:p>

int pageIndex = 0;

//Otherwise, loop through all the pages

foreach (Aspose.Pdf.Page pdfPage in pdfDocument.Pages)



//Calc the out file path

string outFilePath = "c:/pdftest/Test_OptRemoveUnusedStreams_Replaced" + "_" + (pageIndex).ToString().PadLeft(3, '0') + ".pdf";

//Create the new doc

Aspose.Pdf.Document newDocument = new Aspose.Pdf.Document();


Document.OptimizationOptions optOptions = new Document.OptimizationOptions();

optOptions.RemoveUnusedStreams = true; // Removing unused streams was resulting in errors on split page# 3





Yes, this issue is resolved when using Aspose.Pdf for .NET 11.3.0.

Hi Gurjeet,

Thanks for the acknowledgement. We are glad to hear that your problem is resolved. Please continue using our API’s and in the event of any further query, please feel free to contact.