Exception thrown while saving PDF to stream

Hello,

We have come across the following issue. While trying to save the file with empty info we get an exception:
System.InvalidOperationException : Unable to build stream based on pdf document
----> GemBox.Pdf.InvalidPdfDictionaryEntryException : Dictionary entry value is not of type dictionary.

In case we read something from the Info object e.g. var author = document.Info.Author; before saving, everything works fine.

The code is basically:

var document = PdfDocument.Load(stream);
document.CloseStream = closeStream;

 foreach (var page in document.Pages)
 {
     page.Content.Elements
         .All(page.Transform)
         .Remove(e => e.ElementType is PdfContentElementType.Text || e.ElementType is PdfContentElementType.Path);
 }

var resultStream = new MemoryStream();
document.Save(resultStream); 

Could you please suggest if there is a bug, or if there is something on our side that can be adjusted?

Unfortunately, we cannot share the sample document

Hi,

Can you please send us your input PDF (the one you’re passing to PdfDocument.Load) so we can investigate it?

Regards,
Mario

Hello Mario,

We cannot share the sample document as it contains the customer’s PII. We have not found a way to replicate the issue with a different file.

Would you be able to progress with this issue without a sample?

Thank you,
Oleksandr

Hi Oleksandr,

Unfortunately, it won’t be possible to resolve this issue without reproducing it.

Can you please try using the snippet code on the following post to try to remove the confidential data from your PDF file:

After that, if you can still reproduce the same issue, please send us that PDF file so we can investigate it.

Regards,
Mario

Hello Mario,

I am able now to share the PDF that is causing the trouble.
Sending it over the email!

Thank you!

Please try again with this NuGet package:

Install-Package GemBox.Pdf -Version 2025.3.110-hotfix

Note that this is a hidden (unlisted) version. To install it, you’ll need to run the above command on the NuGet Package Manager Console (Tools → NuGet Package Manager → Package Manager Console).

Does this solve your issue?

Hi again, Mario!

The package you provided fixed the issue!

Thanks much!