Inserting image into pdf in Linux not working

Hello All,

I am using gembox.pdf to add a png image into a pdf file. It is working fine in windows but not in linux (I get a black square).
I am using .NET5.
Can you please advise what i could possibly been doing wrong?
Code snippets:

Note: I got this error initially but it was gone after i installed:
apt-get update && apt-get install -y apt-utils libgdiplus libc6-dev

The type initializer for ‘Gdip’ threw an exception.
System.TypeInitializationException: The type initializer for ‘Gdip’ threw an exception.
—> System.DllNotFoundException: Unable to load shared library ‘libgdiplus’ or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: liblibgdiplus: cannot open shared object file: No such file or directory
at System.Drawing.SafeNativeMethods.Gdip.GdiplusStartup(IntPtr& token, StartupInput& input, StartupOutput& output)
at System.Drawing.SafeNativeMethods.Gdip…cctor()
— End of inner exception stack trace —
at System.Drawing.SafeNativeMethods.Gdip.GdipLoadImageFromDelegate_linux(StreamGetHeaderDelegate getHeader, StreamGetBytesDelegate getBytes, StreamPutBytesDelegate putBytes, StreamSeekDelegate doSeek, StreamCloseDelegate close, StreamSizeDelegate size, IntPtr& image)
at System.Drawing.Image.InitializeFromStream(Stream stream)
at System.Drawing.Bitmap…ctor(Stream stream)
at GemBox.Pdf.Content.PdfImage.Load(Stream stream, ImageLoadOptions options)
at GemBox.Pdf.Content.PdfImage.Load(Stream stream)

Thanks

Hi Raed,

GemBox components currently have dependency to System.Drawing.Common which uses “libgdiplus” package on Linux. So, please try installing that package:

sudo apt install libgdiplus

Does this solve your issue?

Also just as an FYI, we’re currently in the process of removing this dependency.

Regards,
Mario

Dear mario.gemboxm
I also have the same issue.
I added “RUN apt-get update && apt-get install -y libgdiplus” in Dockerfile, but the issue not resolve, I still see a black square instead of a image like window server.

Hi,

Please check our Docker example:

Have you added the following packages to your project:

<PackageReference Include="HarfBuzzSharp.NativeAssets.Linux" Version="*" />
<PackageReference Include="SkiaSharp.NativeAssets.Linux" Version="*" />

Regards,
Mario

Hi mario.gembox,

I added both HarfBuzzSharp.NativeAssets.Linux and SkiaSharp.NativeAssets.Linux by NuGet but Issue not resolved.


Where else can i check?

Hi,

Please create a small Visual Studio project that you can share with us and send the project to our email (see the Contact page).

Regards,
Mario