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
375 stars 67 forks source link

NotSupportedException: Current platform is not supported #28

Closed ITaluone closed 3 years ago

ITaluone commented 3 years ago

Hi,

I've installed the NuGet package according to the documentation (README). But if I want to convert HTML to PDF this error shows up. Am I missing something here?

I'm running this on Windows 10 1909 x64, but in further process I want this to run inside an ASP.NET core 3.1 project on Ubuntu.

Thanks for any advice

Edit: Message: Current platform is not supported

Stacktrace: at WkHtmlToPdfDotNet.ModuleFactory.GetModule() at WkHtmlToPdfDotNet.PdfTools.Load() at WkHtmlToPdfDotNet.BasicConverter.Convert(IDocument document) at WkHtmlToPdfDotNet.SynchronizedConverter.<>c__DisplayClass5_0.b__0() at System.Threading.Tasks.Task`1.InnerInvoke() at System.Threading.Tasks.Task.Execute()

ramson12 commented 2 years ago

Unable to load native library. The platform may be missing native dependencies (libjpeg62, etc). Or the current platform is not supported.

Hey I got this error when hosted on Linux server . It works fine on my windows machine but when I host to linux serve I get above error help please

HakanL commented 2 years ago

@ramson12 Have you checked if you have all the dependencies installed?

ramson12 commented 2 years ago

Can you please help me how I can install dependencies Thank you

HakanL commented 2 years ago

@ramson12 The easiest is to install the wkhtmltopdf package, the WkHtmlToPdf-DotNet is just a wrapper around the native library.

ramson12 commented 2 years ago

@HakanL i have only added Haukcode.WkHtmlToPdfDotNet from Nuget manager.

HakanL commented 2 years ago

@ramson12 I understand that, but this is just a wrapper for the native library wkhtmltopdf, you need to make sure your platform has all the necessary dependencies for the wkhtmltopdf library, this NuGet package can't do that for you.

DanielBruch commented 2 years ago

it worked for me after registering the runtimes.

after 5 hours of debugging and testing, I checked, and during the installation, it didn't register the Runtimes. I added the following command in Docker and it worked 100%

ldconfig -p | grep 'libwkhtml' /usr/local/lib/runtimes/libwkhtmltox.so libwkhtmltox.so

after that it worked normally

HakanL commented 2 years ago

@DanielBruch I wonder if that just bypassed the logic that tries to find the runtime, it shouldn't be necessary to do that step, so it's more of a workaround. I wonder if this may be related to #72, maybe you can try the new 1.5.71 NuGet package, maybe that fix helps this scenario as well?

DanielBruch commented 2 years ago

@HakanL
apologies for the delay. I tested it again on another Server on Ubuntu 18.04 and it had the same errors. lack of libjpeg62and Current platform is not supported. Even installing libjpeg62it didn't show resolution

I downloaded the SO File from https://wkhtmltopdf.org/downloads.html and declared SO as in the above comment.

ldconfig -p | grep 'libwkhtml' /usr/local/lib/runtimes/libwkhtmltox.so libwkhtmltox.so

After declaring the SO, it worked perfectly

Edited: I tested in version 1.5.71 as you requested

HakanL commented 2 years ago

Thanks for testing Daniel, I haven't heard of anyone else having to register the native library. You don't happen to have this testable in a docker container do you? Without that it's hard to know if it's something related to your Ubuntu instance.

saumyeN commented 2 years ago

Hi I am using .NET core Azure functions app getting the error mentioned above.

"One or more errors occurred. (Unable to load native library. The platform may be missing native dependencies (libjpeg62, etc). Or the current platform is not supported.)". See the function execution logs for additional details.". See the function execution logs for additional details."

(Inner Exception #0) System.NotSupportedException: Unable to load native library. The platform may be missing native dependencies (libjpeg62, etc). Or the current platform is not supported. [2022-05-06T17:08:27.778Z] at WkHtmlToPdfDotNet.ModuleFactory.GetModule() [2022-05-06T17:08:27.781Z] at WkHtmlToPdfDotNet.PdfTools.Load() [2022-05-06T17:08:27.784Z] at WkHtmlToPdfDotNet.BasicConverter.Convert(IDocument document) [2022-05-06T17:08:27.788Z] at WkHtmlToPdfDotNet.SynchronizedConverter.<>c__DisplayClass4_0.b0() [2022-05-06T17:08:27.792Z] at System.Threading.Tasks.Task`1.InnerInvoke() [2022-05-06T17:08:27.795Z] at System.Threading.Tasks.Task.<>c.<.cctor>b274_0(Object obj) [2022-05-06T17:08:27.802Z] at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state) [2022-05-06T17:08:27.806Z] --- End of stack trace from previous location where exception was thrown ---

Which solutions actualy solves this problem ? Can you please guide step by step. This in local environment, but the same issue occures in the server as well.

HakanL commented 2 years ago

@saumyeN Most likely you're missing some native dependency, try to install the native library and see what it installs. Could also be that it doesn't work with native libraries in Azure consumption plan.

saumyeN commented 2 years ago

Can you suggest where I can get the native library ? And how to install it ?

HakanL commented 2 years ago

Can you suggest where I can get the native library ? And how to install it ?

You'll find all the details on their project page: https://wkhtmltopdf.org/

Luisalvarenga commented 1 year ago

In my case that I was using AWS and Centos 7 I had to follow this steps

1- install: libgdiplus-2.10-10.el7.x86_64 2- Add the files libwkhtmltox (with extensions .dll, .dylib, .so) and set their Compile Action as Content and Copy directory as: Always

With that everything wired up now is working perfectly.

HakanL commented 1 year ago

You shouldn't have to add the native binaries manually, they should be added during the build.

rmalca commented 1 year ago

I'm having trouble implementing this library on Amazon Linux 2. I always get this message and I don't know what might be missing:

"Unable to load native library. The platform may be missing native dependencies (libjpeg62, etc). Or the current platform is not supported."

FROM public.ecr.aws/lambda/dotnet:7

WORKDIR /var/task

RUN rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm

RUN yum install -y \
    fontconfig \
    wget \
    libX11 \
    libXext \
    libXrender \
    libjpeg \
    openssl \
    xorg-x11-fonts-75dpi \
    xorg-x11-fonts-Type1 \
    libgdiplus \
    ca-certificates \
    zlib-devel

RUN rpm -Uvh https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-1/wkhtmltox-0.12.6-1.amazonlinux2.x86_64.rpm

RUN mkdir /opt/lib
RUN ln -s /usr/local/lib/libwkhtmltox.so /usr/lib/libwkhtmltox.so
RUN ln -s /usr/local/lib/libwkhtmltox.so /opt/lib/libwkhtmltox.so

COPY "bin/Release/lambda-publish"  .
HakanL commented 1 year ago

You're missing some native dependencies. Try to install/load the native library wkhtmltopdf and once you got that working this wrapper should be fine.

rmalca commented 1 year ago

For anyone using AWS Toolkit for Visual Studio and having the same problem, I noticed that for some reason the "libwkhtmltox.so" binary is not copied to "runtimes/linux-x64/native/" so basically you have to create a COPY once installed.

FROM public.ecr.aws/lambda/dotnet:7

WORKDIR /var/task

RUN yum install -y \
        libX11 \
        libXext \
        libXrender \
        libjpeg \
        openssl \
        xorg-x11-fonts-75dpi \
        xorg-x11-fonts-Type1 \
    && rpm -U https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-1/wkhtmltox-0.12.6-1.amazonlinux2.x86_64.rpm \
    && mkdir -p ./runtimes/linux-x64/native \
    && cp /usr/local/lib/libwkhtmltox.so ./runtimes/linux-x64/native/libwkhtmltox.so \
    && rpm -e wkhtmltox-0.12.6-1.amazonlinux2.x86_64

COPY "bin/Release/lambda-publish"  .
HakanL commented 1 year ago

@rmalca So you shouldn't actually install the native library, it's already part of this wrapper, I was just suggesting it as a way to determine which dependencies are required. It may work but your image will be larger than necessary.

rmalca commented 1 year ago

@rmalca So you shouldn't actually install the native library, it's already part of this wrapper, I was just suggesting it as a way to determine which dependencies are required. It may work but your image will be larger than necessary.

Got it, I made a change to my Dockerfile reducing the image size by 79MB. I must include the native library installation as the "libwkhtmltox.so" file is not being copied at publish time via the AWS Toolkit.

image image

shivsimi commented 1 year ago

@rmalca - are you able to fix the issue. is it working now?

I am also facing same error when deployed in aws lambda as image. I noticed that file libwkhtmltox in ./runtimes/linux-x64/native is not being picked by code and throwing the similar error. I have added x86 path also. then it worked.

Added below lines in docker RUN mkdir -p ./runtimes/linux-x86/native \ && cp /usr/local/lib/libwkhtmltox.so ./runtimes/linux-x86/native/libwkhtmltox.so

I am not sure whether this is the right way to do it or not. but it worked.

HakanL commented 1 year ago

The publish should copy the native files, if not then that part should be troubleshooted. Copying the file is a workaround, which may be okay until the publish has been figured out.

SaiGaneshKrishnan commented 7 months ago

Can we please provide the docker command for installing native library and copying them at runtime via docker? Trying for almost a day, but couldn't figure it out. @HakanL

HakanL commented 7 months ago

@SaiGaneshKrishnan Not sure what you mean, perhaps you can use the docker example in this repo and go from there.