DinkToPdf dll not found libwkhtmltox

Viewed 4507

I am developing a .net5.0 web api and i am getting the following error while using DinkToPdf:

DllNotFoundException: Unable to load DLL 'libwkhtmltox' or one of its dependencies: The specified module could not be found. (0x8007007E)

I have followed this tutorial, with a few exceptions:

  • added the service added the service, which was not done in the tutorial

    services.AddSingleton(typeof(IConverter),
             new SynchronizedConverter(new PdfTools()));
    ...
    services.AddScoped<IPdfService, PdfService>();
    
  • named the services differently, but that shouldn't matter

  • installed it via NuGet instead of Install-Package DinkToPdf

  • my project is just an API, frontend is not in C#, shouln't matter sincer the error is here:

    return this._converter.Convert(htmlToPdfDocument);
    

Did everything else like in the tutorial.

4 Answers

What is happening there is you are missing the dlls under your project directory. enter image description here

you can get them here DinkToPdf dlls and include them in your project.

For me adding this into the csproj file resolved the issue -

<ItemGroup>
  <None Remove="libwkhtmltox.dll" />
</ItemGroup>

<ItemGroup>
  <EmbeddedResource Include="libwkhtmltox.dll">
    <CopyToOutputDirectory>Always</CopyToOutputDirectory>
  </EmbeddedResource>
</ItemGroup>

You can run below and it will install dlls into bin. Make sure copy those dlls into root directory

Install-Package DinkToPdfCopyDependencies -Version 1.0.8

Related