In this tutorial, we will implement a PDF exporter functionality. We will use open source DinkToPdf library to convert HTML to PDF.
Using DinkToPdf Library
First, we install DinkToPdf package to .application project.

Then, we need to download the library from GitHub repository and copy v0.12.4 folder to inside of “/aspnet_core/src/{ProjectName}.Web.Mvc/wkhtmltox” folder that we have created.


Finally, we need to add these lines to {ProjectName}.Web.Mvc.csproj:
<ItemGroup>
<None Update="log4net.config">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</None>
<None Update="wkhtmltox\v0.12.4\32 bit\libwkhtmltox.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</None>
<None Update="wkhtmltox\v0.12.4\32 bit\libwkhtmltox.dylib">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</None>
<None Update="wkhtmltox\v0.12.4\32 bit\libwkhtmltox.so">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</None>
<None Update="wkhtmltox\v0.12.4\64 bit\libwkhtmltox.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</None>
<None Update="wkhtmltox\v0.12.4\64 bit\libwkhtmltox.dylib">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="wkhtmltox\v0.12.4\64 bit\libwkhtml
andrei997 4 years ago
Hello, I have done exactly what you have explained in this article. On my local machine everything works fine, but when I am deploying to Heroku I get this error: "Unhandled exception. System.DllNotFoundException: Unable to load shared library '/app/heroku_output/wkhtmltox\64bit\libwkhtmltox' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: /app/heroku_output/wkhtmltox/64bit/libwkhtmltox: cannot open shared object file: No such file or directory". If i run bash on heroku I can see in folder output the libraries for 32 and 64 bit. Can you give me a hint on this problem? Thank you!
andrei997 4 years ago
Hello, I have done exactly what you have explained in this article. On my local machine everything works fine, but when I am deploying to Heroku I get this error: "Unhandled exception. System.DllNotFoundException: Unable to load shared library '/app/heroku_output/wkhtmltox\64bit\libwkhtmltox' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: /app/heroku_output/wkhtmltox/64bit/libwkhtmltox: cannot open shared object file: No such file or directory". If i run bash on heroku I can see in folder output the libraries for 32 and 64 bit. Can you give me a hint on this problem? Thank you!