![]() The Wkhtmltopdf.NetCore package expects a Windows folder inside the folder you specified in the setup. Download the most recent version of wkhtmltopdf for Windows from and place it in the directory wkhtmltopdf\Windows in your project folder. Having binary files in Git isn't ideal, but I'm sure you will find a solution that fits your temper. So, you are left with either including the executable in your source code or building a NuGet package and hosting it on an internal NuGet feed (Azure DevOps and MyGet both offer NuGet servers).įor this post, I'll include the executable directly in the source code. In my experience, using one of these packages can be a problem since they typically include the version of wkhtmltopdf that the creator needed and haven't been updated since that. People built NuGet packages (like wkhtmltopdf.圆4). To include wkhtmltopdf in your project, you need to decide how you want to include it. This means that a bundled version of wkhtmltopdf would make it harder to keep up with new versions of wkhtmltopdf. New versions of wkhtmltopdf are released and there is no official NuGet package for it. You might wonder why Wkhtmltopdf.NetCore doesn't come with this dependency, but that's a good thing. The "wkhtmltopdf" parameter is the path to the wkhtmltopdf executable, that you will need to provide manually. Call the AddWkhtmltopdf method in the ConfigureServices method in Startup.cs: public void ConfigureServices(IServiceCollection services) Wkhtmltopdf.NetCore is a free wrapper of wkhtmltopdf that also integrates nicely with ASP.NET Core. ![]() Next, install the Wkhtmltopdf.NetCore NuGet package: Install-Package Wkhtmltopdf.NetCore To start generating PDF files, create a new ASP.NET Core MVC 3.1 project. For now, I will show you how to create a similar PDF generating feature for free. To be fair, we chose NReco.PdfGenerator (paid component) for our service. ![]() Luckily, a lot of open source projects wrapping the usage of wkhtmltopdf exists out there. Calling a CLI from a web app isn't exactly code you want to be displayed in your source code. wkhtmltopdf is a command-line tool able to generate a PDF from HTML, available for most operating systems. Pretty much all PDF generating packages are based on wkhtmltopdf. In this post, I'll show you how to generate a PDF file from an ASP.NET Core (MVC) view.īack when we implemented our invoices on elmah.io, I was looking for a good PDF component for our invoicing service (ASP.NET MVC at the time but now upgraded to core). Whether it is generating an invoice or a report of data, PDF files are still an essential part of most web applications. No matter what system I have been working on, generating PDF files already snuck in somehow. Written by Thomas Ardal, February 25, 2020
0 Comments
Leave a Reply. |