GemBox Support Forum

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)


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.