StackOverflowException with OptimizeResources with UnembedFonts


I am getting a StackOverflowException when using UnembedFonts with OptimizeResources, I was able to reproduce in a sample app.

Sample code:

MemoryStream uncompressedMemoryStream = GetPDFFileAsStream();
Document compressedPDFDocument = new Document(uncompressedMemoryStream);

compressedPDFDocument.OptimizeSize = true;

OptimizationOptions optimizationOptions = new OptimizationOptions
    LinkDuplcateStreams = true,
    RemovePrivateInfo = true,
    RemoveUnusedObjects = true,
    RemoveUnusedStreams = true,
    UnembedFonts = true


When I comment out the UnembedFonts = true I no longer get the exception.

My Environment:

  • .NET Framework 4.7.2
  • Aspose.PDF 19.6.0 (highest version currently able to use)



Would you kindly share your sample PDF document with us, so that we can test the scenario in our environment and address it accordingly.


How do I upload the PDF privately?
This document possibly contains sensitive information.


I messaged a dropbox link to you with the PDF.



We were able to replicate the issue in our environment while using Aspose.PDF for .NET 19.10 with following code snippet:

Document doc = new Document(dataDir + @"example.pdf");
var optimizationOptions = new Aspose.Pdf.Optimization.OptimizationOptions();
optimizationOptions.RemoveUnusedObjects = true;
optimizationOptions.RemoveUnusedStreams = true;
optimizationOptions.RemovePrivateInfo = true;
optimizationOptions.LinkDuplcateStreams = true;
optimizationOptions.UnembedFonts = true;
doc.Save(dataDir + @"ExampleOptimized_19.10.pdf");

We have logged an issue as PDFNET-47229 in our issue tracking system for further investigation. We will look into details of the issue and keep you posted with the status of its correction. Please be patient and spare us little time.

We are sorry for the inconvenience.