I am using Select.HtmlToPdf.NetCore(18.3.0) to convert Html to pdf in Dotnetcore 2.1. It is perfectly working in local environment but when hosted with Docker it throws an error saying,
{"fileName":"System.TypeInitializationException: The type initializer for 'Gdip' threw an exception. ---> System.DllNotFoundException: Unable to load shared library 'libdl' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: liblibdl: cannot open shared object file: No such file or directory\n at Interop.Libdl.dlopen(String fileName, Int32 flag)\n at System.Drawing.SafeNativeMethods.Gdip.LoadNativeLibrary()\n at System.Drawing.SafeNativeMethods.Gdip..cctor()\n --- End of inner exception stack trace ---\n at System.Drawing.SafeNativeMethods.Gdip.GdipNewPrivateFontCollection(IntPtr& fontCollection)\n at SelectPdf.Lib.ᡜ..ctor()\n at SelectPdf.Lib...ctor()\n at SelectPdf.Lib...ctor(ᡏ A_0, A_1)\n
at SelectPdf.HtmlToPdf.ᜁ(String A_0, String A_1, String A_2, String A_3, Boolean A_4)\n at SelectPdf.HtmlToPdf.ConvertHtmlString(String htmlString)
I have tried by adding these set of lines in Dockerfile, but still having the same error.
FROM microsoft/dotnet:2.1-aspnetcore-runtime AS base
RUN apt-get update
RUN apt-get install -y apt-utils
RUN apt-get install -y libgdiplus
RUN ln -s /usr/lib/libgdiplus.so /usr/lib/gdiplus.dll
WORKDIR /app
EXPOSE 80
I know It is an old question but I encountered this problem lately and I would like to share with my solution.
Select.HtmlToPdf.NetCore do not work on linux
Just do not. If you already have generated string with html I would advise you to find this nuget: Haukcode.DinkToPdf
To find some tutorials just google DinkToPdf. Haukcode is just updated and more docker friendly version.
some dockerfile stuff:
FROM microsoft/aspnetcore:2.0.0 as Base
RUN apt-get update
RUN apt-get install -y apt-utils
RUN apt-get install -y libgdiplus
RUN apt-get install -y libc6-dev
RUN ln -s /usr/lib/libgdiplus.so/usr/lib/gdiplus.dll
...
I hope it will help someone :)
this worked for me. I'm running a Debian server, using System.Drawing.Common 4.7.0
RUN apt-get update \
&& apt-get install -y --allow-unauthenticated \
libc6-dev \
libgdiplus \
libx11-dev \
&& rm -rf /var/lib/apt/lists/*
You need to install libc6-dev
in your Docker container. You can install libc6-dev by running the following command:
RUN apt-get install -y libc6-dev
Let me know how that goes.
I was facing the same problem too using iTextSharp 5.5.13.1 and the way I've solved is combine @Frederik Carlier's solution in my Dockerfile:
RUN apt-get update && apt-get -y install libxml2 libgdiplus libc6-dev
After that, i've restarted Rancher Container and Rancher User Stack and it works fine.
(Runtime used: FROM microsoft/dotnet:2.2-aspnetcore-runtime)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With