Unable to load shared library 'libwkhtmltox' or one of its dependencies

829 Views Asked by At

I am using https://github.com/rdvojmoc/DinkToPdf DinkToPDF library to convert HTML to PDF.

Everything working fine in the local environment.

But in the Production environment, it throws some errors when converting html to pdf.

System.AggregateException: One or more errors occurred. (Unable to load shared library 'libwkhtmltox' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: liblibwkhtmltox: cannot open shared object file: No such file or directory) ---> System.DllNotFoundException: Unable to load shared library 'libwkhtmltox' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: liblibwkhtmltox: cannot open shared object file: No such file or directory at DinkToPdf.WkHtmlToXBindings.wkhtmltopdf_init(Int32 useGraphics)

I had tried below solutions, but they did not work.

  1. I added DinkToPdfCopyDependencies package but it works loclly but not works in Production env

<PackageReference Include="DinkToPdfCopyDependencies" Version="1.0.8" />

  1. then I copied package manually and
       <None Update="libwkhtmltox.dll">
           <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
           <CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
       </None>
       <None Update="libwkhtmltox.dylib">
           <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
           <CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
       </None>
       <None Update="libwkhtmltox.so">
           <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
           <CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
       </None>
   </ItemGroup> 
</Project>

enter image description here

This also works in local environment, but when did not work in the Production environment.

Anyone who works with DinkToPDF, please help me fix this issue.

OR

Does anyone know any libraries to covert html to pdf in .NET 6 (Free and It should has MIT license)

Please suggest something. I am struggling with more than two days.

1

There are 1 best solutions below

0
Jonathan Willcock On

I had a similar issue with the libwkhtmltox dll (worked locally, but not on server). In my case it was due to some of the dependencies on the server. To fix this, all I had to do was to run the appropriate VC update package, which you can find here.