DinkToPdf icon indicating copy to clipboard operation
DinkToPdf copied to clipboard

DllNotFoundException: Unable to load DLL 'libwkhtmltox' or one of its dependencies

Open Axlii50 opened this issue 3 years ago • 4 comments

DinkToPdf.WkHtmlToXBindings.wkhtmltopdf_init(int useGraphics) DinkToPdf.PdfTools.Load() DinkToPdf.BasicConverter.Convert(IDocument document) RegCOM_Test.Controllers.Main.RecordCreatePDF() in Main.cs + var file = converter.Convert(pdf); lambda_method(Closure , object , object[] ) Microsoft.Extensions.Internal.ObjectMethodExecutor.Execute(object target, object[] parameters) Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor+SyncActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, object controller, object[] arguments) Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeActionMethodAsync() Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(ref State next, ref Scope scope, ref object state, ref bool isCompleted) Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeNextActionFilterAsync() Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context) Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(ref State next, ref Scope scope, ref object state, ref bool isCompleted) Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeInnerFilterAsync() Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResourceFilter>g__Awaited|24_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, object state, bool isCompleted) Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context) Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(ref State next, ref Scope scope, ref object state, ref bool isCompleted) Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeFilterPipelineAsync() Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope) Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger) Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context) Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)

image as embeded resources

whats wrong with it ?

Axlii50 avatar Dec 07 '20 16:12 Axlii50

@Axlii50 can you provide some more details on your environment? We are encountering the same issue running the container image mcr.microsoft.com/dotnet/core/aspnet:2.1-alpine3.12

We are trying to move from running on Windows to a Linux container and this is a blocker.

ChristianHartTE avatar Dec 15 '20 20:12 ChristianHartTE

@Axlii50 I was able to get Dink working by downgrading Alpine to 3.7. I am not very happy with having to do that so I am still looking for other options.

chrishart0 avatar Dec 16 '20 01:12 chrishart0

We have Dink and libwk running on FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build but there were some ssl issues with it so in the runner config I had to do this

FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim AS final
RUN apt-get update && apt-get install -y libgdiplus wget libfontenc1 x11-common xfonts-encodings fontconfig xfonts-75dpi xfonts-base xfonts-utils lsb-base 

WORKDIR /tmp
RUN wget https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-1/wkhtmltox_0.12.6-1.buster_amd64.deb && dpkg -i wkhtmltox_0.12.6-1.buster_amd64.deb

and then in Startup.cs in ConfigureServices we have this

var context = new CustomAssemblyLoadContext(); // nahrani knihovny pro pdf
      if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
      {
        Console.WriteLine("Loading /usr/local/lib/libwkhtmltox.so"); // this is where the installed version is
        context.LoadUnmanagedLibrary("/usr/local/lib/libwkhtmltox.so");
      }
      else
      {
        context.LoadUnmanagedLibrary(Path.Combine(currentDirectory, "libwkhtmltox.dll"));
      }

It works quite fine except we cannot generate chartjs charts in the pdf..

OndrejValenta avatar Apr 29 '21 12:04 OndrejValenta

Adding this package resolved the issue for me: https://www.nuget.org/packages/DinkToPdfCopyDependencies

zamgill avatar Mar 15 '22 23:03 zamgill