How to install WebKit HTML converter using NuGet package manager in ASP.NET MVC?
The Syncfusion HTML to PDF converter is a .NET PDF library for converting webpages, SVG, MHTML and HTML to PDF using C#. It is reliable and accurate. The result preserves all graphics, images, text, fonts, and the layout of the original HTML document or webpage. You can install the required assemblies and binaries in the .NET Framework application by using the NuGet package manager.
Refer to this documentation link for installing NuGet packages.
Steps to install WebKit HTML converter using NuGet package manager:
- Create a new ASP.NET MVC application project.
- Install the Syncfusion.HtmlToPdfConverter.QtWebKit.AspNet.Mvc5 NuGet package as a reference to your .NET Framework applications from NuGet.org.
- Copy the QtBinaries folder from the installed HtmltoPdfConverter package and paste it into the folder, which contains the HTMLtoPDF.csproj file.
- Then, include the QtBinaries folder in a project and set Copy to output directory as copy always for all the QtBinaries (All files including inner folders and files) assemblies.
- Add a button to convert HTML to PDF in index.cshtml.
@using (Html.BeginForm("ExportToPDF", "Home", FormMethod.Post)) { <input type="submit" value="Convert HTML to PDF" /> }
- Include the following namespaces and code snippet for converting HTML to PDF.
C#
using Syncfusion.HtmlConverter; using Syncfusion.Pdf; using System.IO;
public ActionResult ExportToPDF() { //Initialize HTML to PDF converter HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(HtmlRenderingEngine.WebKit); WebKitConverterSettings settings = new WebKitConverterSettings(); //Set WebKit path settings.WebKitPath = Server.MapPath("~/QtBinaries/"); //Assign WebKit settings to HTML converter htmlConverter.ConverterSettings = settings; //Convert a URL to PDF with HTML converter PdfDocument document = htmlConverter.Convert("http://www.google.com"); //Save the PDF document MemoryStream stream = new MemoryStream(); document.Save(stream); return File(stream.ToArray(), System.Net.Mime.MediaTypeNames.Application.Pdf, "HTMLtoPDF.pdf"); }
A complete working sample can be downloaded from HTMLtoPDF.zip.
By executing the program, you will get the PDF file as follows.
Take a moment to peruse the documentation, where you will find other options like Html string to PDF, partial webpage to PDF, Html to single PDF page, and Html to PDF conversion using IE Rendering with code examples.
Click here to explore the rich set of Syncfusion Essential PDF features.
An online sample link to Convert Html To PDF document.
Starting with v16.2.0.x, if you reference Syncfusion assemblies from trial setup or from the NuGet feed, include a license key in your projects. Refer to link to learn about generating and registering Syncfusion license key in your application to use the components without trail message.
Conclusion
I hope you enjoyed learning about how to install WebKit HTML converter using NuGet package manager in ASP.NET MVC.
You can refer to our ASP.NET MVC PDF feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our ASP.NET MVC PDF example to understand how to create and manipulate data.
For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.
If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!