我正在使用Select.HtmlToPdf.NetCore(18.3.0)在Dotnetcore 2.1中将HTML转换为pdf。它可以在本地环境中完美运行,但是当与Docker托管时,会引发错误消息,
{“ fileName”:“ System.TypeInitializationException:'Gdip'的类型初始值设定项引发了异常。---> System.DllNotFoundException:无法加载共享库'libdl'或其依赖项之一,以帮助诊断加载问题,请考虑设置LD_DEBUG环境变量:liblibdl:无法打开共享对象文件:Interop.Libdl.dlopen(字符串文件名,Int32标志)处没有这样的文件或目录\ n,System.Drawing.SafeNativeMethods.Gdip.LoadNativeLibrary() \ n在System.Drawing.SafeNativeMethods.Gdip..cctor()\ n-内部异常堆栈跟踪的结尾--- \ n在System.Drawing.SafeNativeMethods.Gdip.GdipNewPrivateFontCollection(IntPtr&fontCollection)\ n在SelectPdf。 Lib.?..ctor()\n在SelectPdf.Lib.?..ctor()\n在SelectPdf.Lib.?..ctor(?A_0,?A_1)\ n
在SelectPdf.HtmlToPdf.ConvertHtmlString(String htmlString)处(字符串A_0,字符串A_1,字符串A_2,字符串A_3,布尔值A_4)\ n
我尝试通过在Dockerfile中添加这些行集来进行尝试,但是仍然存在相同的错误。
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
Run Code Online (Sandbox Code Playgroud)
这对我有用。我正在运行 Debian 服务器,使用 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/*
Run Code Online (Sandbox Code Playgroud)
我知道这是一个老问题,但是最近我遇到了这个问题,我想与我分享一下解决方案。
Select.HtmlToPdf.NetCore在linux上
不起作用。如果您已经用html生成了字符串,我建议您找到这个nuget:Haukcode.DinkToPdf
要查找一些教程,只需google DinkToPdf。Haukcode刚刚更新,并且对docker更友好。
一些dockerfile的东西:
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
...
我希望它可以帮助某人:)
您需要安装libc6-dev在 Docker 容器中。您可以通过运行以下命令来安装 libc6-dev:
RUN apt-get install -y libc6-dev
Run Code Online (Sandbox Code Playgroud)
让我知道进展如何。
| 归档时间: |
|
| 查看次数: |
2128 次 |
| 最近记录: |