簡體   English   中英

NetCore HTML 轉 PDF 庫在 linux 環境中失敗

[英]NetCore HTML to PDF library fails in linux environment

目前我正在使用SelectPdf基於一些 html 生成一個 pdf 文件。 該庫在 Windows 環境中工作得很好,但是當我在 linux 容器中運行它時它會失敗。

這是我的 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"]

哪個構建得很好,而且工作得很好,直到我使用了一些 SelectPdf 時間,在這個時間我得到了所有類型的異常

發票-api |

{"EventId":13,"LogLevel":"Error","Category":"Microsoft.AspNetCore.Server.Kestrel","Message":"Connection id "0HMEDQ3A2F2L8", Request id "0HMEDQ3A2F2L8:00220000應用程序拋出未處理的異常。","Exception":"System.TypeInitializationException: \'Gdip\' 的類型初始值設定項拋出異常。---\> System.DllNotFoundException: 無法加載共享庫 \'libgdiplus\'或其依賴項之一。為了幫助診斷加載問題,請考慮設置 LD_DEBUG 環境變量:liblibgdiplus:無法打開共享對象文件:System.Drawing.SafeNativeMethods.Gdip.GdiplusStartup(IntPtr\& token, StartupInput\& 輸入,StartupOutput\& 輸出)在 System.Drawing.SafeNativeMethods.Gdip..cctor() --- 內部異常堆棧跟蹤結束 --- 在 System.Drawing.SafeNativeMethods.Gdip.GdipNewPrivateFontCollection(IntPtr\& fontCollection ) 在 System.Drawing.Text.PrivateFontCollecti on..ctor() 在 SelectPdf.Lib.\ᡟ..ctor() 在 SelectPdf.Lib.\១..ctor() 在 SelectPdf.Lib.\១..ctor(\ᡒ A_0, \ᠠ A_1) 在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, InvoicesourceRequestModel model) /Api/Controllers/InvoicesController.cs:Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.TaskOfIActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments) 的第 80 行,Microsoft.AspNetCore.Mvc.Invokerstructure.ControllerInaction .\ g__Awaited|12_0(ControllerActionInvoker invoker, ValueTask\`1 actionResultValueTask) 在 Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.\ pe scope, Object state, Boolean isCompleted) at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context) at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State\& next, Scope\& scope, Object\\ u0026 state, Boolean\& isCompleted) at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.\ g__Awaited|13_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object State, at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker, .Infrastructure.ResourceInvoker.\ g__Awaited|25_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted) 在 Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrowed(ResourceNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrowedcontext)atMicrosoft. .Mvc.Infrastructure.ResourceInvoker.Next(State\& next, Scope\& scope, Object\& state, Boolean\& isComplete d) 在 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.Invoker.Infrastructure u003CInvokeAsync\>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.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) .\ 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": 應用程序拋出未處理的異常。","ConnectionId":"0HMEDQ3A2F2L8","TraceIdentifier":"0HMEDQ3A2F2L8:00000002","{OriginalFormat}":"Connection id "{ConnectionId}", Request 2 id \ {TraceIdentifier}":應用程序拋出了一個未處理的異常。"}}

我將不勝感激。 或者可以在 linux 容器內運行的庫的任何其他建議,而無需在 dockerfile 或運行容器的主機中進行任何額外的設置。

我不關心性能,而只關心能夠插入庫並正常工作。

SelectPdf網站:

SelectPdf 僅適用於 Windows

您可以嘗試將 C# 包裝器用於wkhtmltopdf (至少其中一些可能需要您手動在容器中安裝 lib 本身)、 iTextSharp或其 LGPL 端口

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM