Articles in this section
Category / Section

How to install WebKit HTML converter using NuGet package manager in ASP.NET MVC?

2 mins read

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:

  1. Create a new ASP.NET MVC application project. Create a MVC project. Create MVC template
  2. Install the Syncfusion.HtmlToPdfConverter.QtWebKit.AspNet.Mvc5  NuGet package as a reference to your .NET Framework applications from NuGet.org. Install packages from NuGet manager.
  3. Copy the QtBinaries folder from the installed HtmltoPdfConverter package and paste it into the folder, which contains the HTMLtoPDF.csproj file. NuGet location pathpaste the Qtbinaries folder to project location.
  4. 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. Include the QtBinaries folder to a project. Set Copy always to QtBinaries
  5. 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" />
    }
    

 

  1. 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. Output Document

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.

Note:

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 forumsDirect-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied