Invalid image stream (The type initializer for 'Gdip' threw an exception.)

Hi,
I’m trying to run the Add Image in an Existing PDF File tutorial on Debian Buster with .NET 6, but I keep getting the Invalid image stream (The type initializer for ‘Gdip’ threw an exception.) exception when doing

page.Resources.Images.Add(imageStream);

I run the latest version of Aspose.Pdf (22.2.0) and have the latest version of Mono (6.12.0.122) installed, so libgdiplus is already installed.
The full message of the exception is the following:

Invalid image stream (The type initializer for 'Gdip' threw an exception.) - - at Aspose.Pdf.XImageCollection.#=z_Q6YKpulfs7I2gbLuA==(Stream #=zczkUVwg=, #=zbzVqcf6w2ID$VMkn_nrNFngrtIjcAmb2mnMo26iS0I9e #=zE$UTqc0=, #=zmQ2IzQQuwJuzpkkhGQkD9mJSEdqKH_ZQZQ== #=zSMvBw_o=, Int32 #=zIpRNwIU=, Image& #=zT6_Ku9o_ub0m, Stream #=zc6Bb1v8wYVivjNqJNj2V1b0=) at Aspose.Pdf.XImageCollection.#=zlC1BBQSsfXc6(Int32 #=zFr7IclI=, Stream #=zczkUVwg=, Int32 #=zIpRNwIU=, Boolean #=zjDoBBJli7d3i, ImageFilterType #=zaaMpFOY=, Byte #=zhJauUT1DRVJ1, Boolean #=zGhIm6j0=, String& #=zMURLBPipZv3I, Stream #=zc6Bb1v8wYVivjNqJNj2V1b0=) at Aspose.Pdf.XImageCollection.#=zlC1BBQSsfXc6(Int32 #=zFr7IclI=, Stream #=zczkUVwg=, Int32 #=zIpRNwIU=, Boolean #=zjDoBBJli7d3i, ImageFilterType #=zaaMpFOY=, String& #=zI8d1Q7g=)

Do you have any ideas on how to solve the issue?
Thanks in advance.

@Gruppo_MutuiOnline_Spa

It looks like that libgdiplus package is missing in your system. Please make sure that it is installed on your machine.

Aspose.PDF requires following two packages in order to run correctly in Linux like systems:

  • libgdiplus
  • msttcorefonts

The fonts should be placed in “/usr/share/fonts/truetype/msttcorefonts” folder (our API scan this folder on Linux like systems). If operating system has other default folder for fonts, you should add following command at the beginning of your code:

FontRepository.Sources.Add(new FolderFontSource("<user's path to ms fonts>"))

If you still face problem, please ZIP and attach your input PDF, image, and code example that you are using to reproduce the same issue at our end.