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
367 stars 66 forks source link

centos8 Error #64

Closed shanxixiaohuozi closed 2 years ago

shanxixiaohuozi 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

HakanL commented 2 years ago

The issue is most likely related to missing dependencies in your environment, it's most likely not an issue with this .NET wrapper.

shanxixiaohuozi commented 2 years ago

I've installed libjpec, but it doesn't work. wkhtmltopdf http://xxx /opt/xxx.pdf but this it works

HakanL commented 2 years ago

Since this is just a wrapper in .NET for the native library, most likely there's some missing dependency in your system.

shanxixiaohuozi commented 2 years ago

i see,thanks

WalissonPires commented 1 year ago

@shanxixiaohuozi Did I manage to solve the problem? I have the same problem with CentOS 7. Running wkhtmltopdf in the terminal works fine. But via C# gives the same error.

How could I know which dependency is missing?

WalissonPires commented 1 year ago

Could someone tell me why running wkhtmltopdf directly from the terminal works and via C# code doesn't?

(I installed wkhtmltopdf as root)

CentOS Linux release 7.9.2009 (Core) wkhtmltopdf 0.12.5 (with patched qt)

HakanL commented 1 year ago

@WalissonPires Most likely it's because the binary that is used in the terminal has other dependencies that are met, than the library that is used by the C# code. There are some ways to figure out what library Linux tries to load, maybe you can try something like that. I'm almost certain it's a dependency problem.

WalissonPires commented 1 year ago

I downloaded the project to my server where I was having the problem and ran some tests.

I added some logs in the ModuleFactory file's try/catch and found the error was as follows:

Unable to load shared library 'runtimes/linux-x64/native/libwkhtmltox' or one of its dependencies. In order to help diagnose loading problems, consider using a tool like strace. If you're using glibc, consider setting the LD_DEBUG environment variable: 

/usr/share/dotnet/shared/Microsoft.NETCore.App/7.0.5/runtimes/linux-x64/native/libwkhtmltox.so: cannot open shared object file: No such file or directory
libpng16.so.16: cannot open shared object file: No such file or directory
/usr/share/dotnet/shared/Microsoft.NETCore.App/7.0.5/runtimes/linux-x64/native/libwkhtmltox: cannot open shared object file: No such file or directory\n/root/WkHtmlToPdf-DotNet/src/TestConsoleApp/bin/Debug/net7.0/runtimes/linux-x64/native/libwkhtmltox: cannot open shared object file: No such file or directory

The lib libpng16.so.16 was missing and I had installed the following libs:

libpng.so.3
libpng.so.3.50.0
libpng12.so.0
libpng12.so.0.50.0
libpng15.so.15
libpng15.so.15.13.0

Apparently CentOS 7 doesn't support libpng16. I found it only for CentOS 8+.

But this only happened when using via C# code. Running wkhtmltopdf via terminal worked fine.

Then I copied the /usr/local/lib/libwkhtmltox.so file (created from the manual installation of wkhtmltopdf ) to the runtimes/linux-x64/native folder of the project. Replacing the version that came from nuget. This solves the problem.

HakanL commented 1 year ago

The native library that is included in the C# project is from the wkhtmltopdf project, and it linked to specific versions of the dependencies. Other compiled libraries may have different dependencies, it doesn't mean much, but the bottom line is if you want to use the included native library then you need to have the exact dependencies met.