HakanL / WkHtmlToPdf-DotNet

C# .NET Core wrapper for wkhtmltopdf library that uses Webkit engine to convert HTML pages to PDF.
GNU Lesser General Public License v3.0
372 stars 67 forks source link

.net 6 One or more errors occurred. (Unable to load native library. The platform may be missing native dependencies (libjpeg62, etc) #69

Closed power911 closed 2 years ago

power911 commented 2 years ago

Hi, we are using WkHtmlToPdfDotNet 1.5.66 with .net 6, and when i try to convert html to pdf, get all time error image

WkHtmlToPdfDotNet supported .net6?

HakanL commented 2 years ago

Yes, .NET6 is supported, the issue is most likely that you're missing a native dependency (like the error message says).

power911 commented 2 years ago

Yes, .NET6 is supported, the issue is most likely that you're missing a native dependency (like the error message says).

How to fix this issue? Do you have any solutions? We get this on Win10

HakanL commented 2 years ago

I recommend that you read through the other issues here to see if you can figure out what's going on. Maybe try the wkhtmltopdf native package first and go from there.

nielslbeck commented 2 years ago

I'm having the same issue. Did you find a solution, @power911?

I'm trying to use the library in an Azure Function. It works on Windows. On Linux and Mac it doesn't work. However, when running from a unit test project it works on my Mac 🤷🏻‍♂️

HakanL commented 2 years ago

@nielslbeck Make sure you're not on a consumption plan in Azure, I don't think they support native libraries.

lackeyi commented 2 years ago

Im having the same issue on S1. I have verified that the /home/site/wwwroot/bin/runtimes/linux-x64/native/libwkhtmltox.so exists. Any suggestions on where to look further?

Thanks!

HakanL commented 2 years ago

Most likely an issue with dependencies, make sure you can run it locally first.

lackeyi commented 2 years ago

I think you are correct. It looks like the dependencies for libwkhtmltopdf.so are not available on the default image for azure functions. Does that sound right to you? I am hoping to avoid using docker if possible. Any help to get the right libs in place is much appreciated.

HakanL commented 2 years ago

Yeah, the native library does require libjpeg, etc. The easiest is to just install the package for the wkhtmltopdf from their site, which will install the dependencies and this wrapper should work.

lackeyi commented 2 years ago

I was hoping to avoid that if at all possible since that will require a custom container. Do you know of anyone that has been able to get this to work in Azure functions without Docker?

HakanL commented 2 years ago

If you have root access to the node then I think installing the native library (wkhtmltopdf) is the best way. If it's a managed container then docker is the best option IMO. In fact, I'm not sure if you can install anything in Azure Functions without it being in Docker?

lackeyi commented 2 years ago

I know on python you can use pip to install libraries which has gotten me around this in the past. However, I do not see a way to do that using the dotnet runtime.

With that said, I switched over to using the Azure functions docker container and was able to get it running locally. I have not had a chance to deploy it to Azure yet but I don't see any reason it wouldn't work there. I will report back if it fails for some reason.

Thanks for putting this library together and for your help!

P.S. Here is the docker file I am using in case it's helpful to someone:

FROM mcr.microsoft.com/dotnet/sdk:6.0 AS installer-env
COPY --from=mcr.microsoft.com/dotnet/core/sdk:3.1 /usr/share/dotnet /usr/share/dotnet

COPY . /src/dotnet-function-app
RUN cd /src/dotnet-function-app && \
    mkdir -p /home/site/wwwroot && \
    dotnet publish *.csproj --output /home/site/wwwroot
FROM mcr.microsoft.com/azure-functions/dotnet:4
ENV AzureWebJobsScriptRoot=/home/site/wwwroot \
    AzureFunctionsJobHost__Logging__Console__IsEnabled=true 

#Added this:
RUN apt-get update \
    && apt-get install -y --allow-unauthenticated wkhtmltopdf \
    && rm -rf /var/lib/apt/lists/*

COPY --from=installer-env ["/home/site/wwwroot", "/home/site/wwwroot"]
HakanL commented 2 years ago

I think you're mixing the "domains". pip for Python installs Python-dependencies, same as NuGet for .NET. But the issue here is that you need native dependencies (native meaning libraries coded in C++, etc, compiled into binaries). Wkhtmltopdf is such a library and that's why you need to install its dependencies outside of the managed domain (Python or .NET). Which you basically need root access to do, which docker allows you. We have a docker example in the source code samples.