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.

img

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.

img

img

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