NullReferenceException in OptimizeResources with LinkDuplcateStreams

I have a relatively large (merged) PDF document with fonts that are partially embedded and want to reduce the size of the document by first unembedding fonts and removing duplicates, then fully embedding the fonts used.




I use the following two-step approach:



input.OptimizeResources(new Document.OptimizationOptions()
{
LinkDuplcateStreams = true,
UnembedFonts = true
});

foreach (Page page in input.Pages)
{
Console.Out.WriteLine("page " + page.Number);
var fonts = page.Resources.Fonts;
if (fonts != null)
{
foreach (Font font in fonts)
{
font.IsSubset = false;
font.IsEmbedded = true;
}
}
}


This works on some input PDF files, but on others it fails with a NullReferenceException:


System.NullReferenceException was unhandled
HResult=-2147467261
Message=Object reference not set to an instance of an object.
Source=Aspose.Pdf
StackTrace:
at . ( ​ , ​ , Int32 )
at . ( , , Int32 )
at . ( ​ , ​ , Int32 )
at . ( ​ , ​ , Int32 )
at . ( ​ , ​ , Int32 )
at . ( , , Int32 )
at . ( ​ , ​ , Int32 )
at . ( ​ , ​ , Int32 )
at . ( ​ , ​ , Int32 )
at . ( , , Int32 )
at . ( ​ , ​ , Int32 )
at . ( , , Int32 )
at . ( ​ , ​ , Int32 )
at . ( , , Int32 )
at . ( ​ , ​ , Int32 )
at . ( ​ , ​ , Int32 )
at Aspose.Pdf.Document. . ( )
at Aspose.Pdf.Document. . ( ​ )
at Aspose.Pdf.Document. . ( ​ )
at Aspose.Pdf.Document. . ( ​ )
at Aspose.Pdf.Document. . ( ​ )
at Aspose.Pdf.Document. . ( ​ )
at Aspose.Pdf.Document. . ( ​ )
at Aspose.Pdf.Document. . ( ​ )
at Aspose.Pdf.Document. . ( ​ )
at Aspose.Pdf.Document. (OptimizationOptions )
at Aspose.Pdf.Document.OptimizeResources(OptimizationOptions strategy)


The version of Aspose.Pdf is 16.11.0.0.




If I change LinkDuplcateStreams to false, then the process runs through, but the fonts are embedded once per page, so the output file gets very big.



Am I doing something wrong? Is there a different way to achieve my goal?

Hi there,


Thanks for your inquriy. It seems it is file specific issue, please share your sample PDF document here, we will test the scenario and will guide you accordingly.

We are sorry for the inconvenience.

Best Regards,

Hello Tilal,

I have attached a sample file that demonstrates the problem.

Hi Christian,

Thanks for using our API's.

I have tested the scenario and have managed to reproduce same problem. For the sake of correction, I have logged it as PDFNET-41888 in our issue tracking system. We will further look into the details of this problem and will keep you posted on the status of correction. Please be patient and spare us little time. We are sorry for this inconvenience.
Hello Nayyer,

Is there an ETA for a fix of this issue?

Best regards,
Christian Clausen

Hi Christian,


Thanks for your inquiry. I am afraid the issue is still pending for investigation, as product team is looking into other issues in the queue, reported earlier. We will notify you as soon as we made some significant progress towards issue resolution.

We are sorry for the inconvenience.

Best Regards,

Hi Guys

Is there any news or ETA of this bug report.
The reason for the follow up is, that we have a Client which has been waiting for more than a year now for a bug fix for this issue, and they are getting kind of impatient.

Any response is most appreciated, thanks.

PS: I am a colleague of Christian, who placed this report originally.

Best regards
Sveinur Thomsen

@sveinurthomsen,

Unfortunately, it is not resolved yet. We have logged an ETA request under the same ticket ID PDFNET-41888 in our bug tracking system. We will let you know once an update is available.

Hello together,

I’ve encountered the same issue, having the font embedded on each page - making the resulting .pdf file extremely big.

Is there a solution to this issue already?

Best Regards

Oliver Fuchsberger

@ofu,

Kindly send us your source PDF document. We will investigate your scenario in our environment and share our findings with you. Your response is awaited.

Hi Imran,

I am also a colleague of Sveinur and Christian, who already replied on this ticket. We are experiencing the same issue in several projects now. As far as I am informed, Christian has providied an example PDF.

The issue with providing example PDFs is that those contain invoice data of end customers which I am not allowed to use (for obvious reasons).

Best Regards

Oliver Fuchsberger

@ofu,

We have already raised the priority of linked ticket ID PDFNET-41888 to maximum level under the free support model. In order to further escalate the priority, we recommend you to post this ticket Id in the paid support forum. Please refer to this helping link: Aspose support options.

Besides this, we recommend our clients to post each their problematic document for the testing purposes. We do not place documents anywhere publicly and take care of the sensitive private documents. In the other way round, you can remove sensitive data or fill dummy data, and then make sure that the problem is reproducible into your environment before sharing with us.

Hi Imran,

is there any new status on this issue? Has ticket ID PDFNET-41888 been solved?

THX
Thomas

@ThoBac

Thanks for contacting support.

We are afraid that issue could not get resolved due to other high priority tasks and implementation. We will surely inform you as soon as we have some certain updates regarding its rectification. Please spare us some time.

We are sorry for the inconvenience.

Hi,

still we are waiting for a solution for this issue.

Is there any progress about it?

Best regards
Philipp

@stauss

We are afraid that earlier logged ticket is not yet resolved. Would you kindly share if you are facing this issue with all type of your PDF documents or with some specific ones? Can you please try using Aspose.PDF for .NET 20.8 at your side and share the feedback with us.