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,
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 generated on 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.
C#
Aspose.Pdf.Document pdfDocument = new Aspose.Pdf.Document("c:/pdftest/Test_OptRemoveUnusedStreams.pdf");
int pageIndex = 0;
// Otherwise, loop through all the pages
foreach (Aspose.Pdf.Page pdfPage in pdfDocument.Pages)
{
++pageIndex;
// 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();
newDocument.Pages.Add(pdfPage);
Document.OptimizationOptions optOptions = new Document.OptimizationOptions();
optOptions.RemoveUnusedStreams = true; // Removing unused streams was resulting in errors on split page# 3
newDocument.OptimizeResources(optOptions);
newDocument.Save(outFilePath);
}
Thanks!
Yes, this issue is resolved when using Aspose.Pdf for .NET 11.3.0.
Hi Gurjeet,