简体   繁体   中英

NetCore HTML to PDF library fails in linux environment

Currently I'm using SelectPdf to generate based on some html a pdf file. The library works just fine in a windows environment, but it fails when I'm running it inside a linux container.

This is my dockerfile:

FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /source_code
COPY . .    
RUN dotnet publish --configuration Release --output dist    

FROM mcr.microsoft.com/dotnet/aspnet:6.0     
WORKDIR /app    
COPY --from=build /source_code/dist .    
EXPOSE 80
EXPOSE 8080
EXPOSE 433    
ENTRYPOINT ["dotnet", "Api.dll"]

Which builds just fine, and it works just fine, that is untill I'm using some the SelectPdf time at which I'm getting all kind of exceptions

invoice-api |

{"EventId":13,"LogLevel":"Error","Category":"Microsoft.AspNetCore.Server.Kestrel","Message":"Connection id "0HMEDQ3A2F2L8", Request id "0HMEDQ3A2F2L8:00000002": An unhandled exception was thrown by the application.","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.GdipNewPrivateFontCollection(IntPtr\& fontCollection) at System.Drawing.Text.PrivateFontCollecti on..ctor() at SelectPdf.Lib.\ᡟ..ctor() at SelectPdf.Lib.\១..ctor() at SelectPdf.Lib.\១..ctor(\ᡒ A_0, \ᠠ A_1) at SelectPdf.HtmlToPdf.\ᜂ(String A_0, String A_1, String A_2, String A_3, Boolean A_4) at SelectPdf.HtmlToPdf.ConvertHtmlString(String htmlString) at Api.Controllers.InvoicesController.Post(Int64 id, InvoiceRequestModel model) in /source_code/Api/Controllers/InvoicesController.cs:line 80 at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.TaskOfIActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments) at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.\ g__Awaited|12_0(ControllerActionInvoker invoker, ValueTask\`1 actionResultValueTask) at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.\ g__Awaited|10_0(ControllerActionInvoker invoker, Task lastTask, State next, Sco d) at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.\ g__Awaited|20_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted) at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.\ g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope) at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.\ g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope) at Microsoft.AspNetCore.Routing.EndpointMiddleware.\ g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger) at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context) at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.ProcessRequests[TContext](IHttpApplication\`1 application)","State":{"Message":"Connection id "0HMEDQ3A2F2L8", Request id "0HMEDQ3A2F2L8:00000002": An unhandled exception was thrown by the application.","ConnectionId":"0HMEDQ3A2F2L8","TraceIdentifier":"0HMEDQ3A2F2L8:00000002","{OriginalFormat}":"Connection id "{ConnectionId}", Request id "{TraceIdentifier}": An unhandled exception was thrown by the application."}}

Or any other suggestions of a library that can be run inside a linux container without having to do any aditional setup in the dockerfile or the host running the container.

From the SelectPdf website:

SelectPdf only works on Windows

You can try using C# wrappers for wkhtmltopdf (at least some of them can require you to install the lib itself in container manually), iTextSharp or it's LGPL port .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM