Getting Started with HiQPdf Chromium for .NET on Windows

HiQPdf Chromium for .NET offers a modern, simple, fast, flexible and powerful tool for creating complex and stylish PDF documents in .NET applications for Windows with just a few lines of C# code, using the integrated HTML to PDF Converter component.

The HTML to PDF converter uses Chromium as its rendering engine, which can process modern HTML, CSS and JavaScript in conformance with the latest standards and technologies.

Compatible Platforms

HiQPdf Chromium for .NET runs natively on 64-bit Windows operating systems. The product runtime is compatible with Windows 10, Windows Server 2016 and later versions of the Windows 64-bit OS.

The .NET library is built for .NET Standard 2.0, which makes it compatible with a wide range of .NET Core and .NET Framework versions starting from .NET Core 2.0 and .NET Framework 4.6.2 up to the latest available versions.

The product can run on Windows without requiring any installation or prior configuration of the operating system. The steps needed to use the library in your application are described below.

The software is also fully compatible with Azure App Service and Azure Functions on Windows. Installation instructions for these platforms are provided in a separate documentation section.

Install NuGet package

Create a new .NET project in Visual Studio and use the NuGet Package Manager from Visual Studio to add a reference to the HiQPdf.Chromium.Windows package from NuGet.

Include HiQPdf.Chromium Namespace

After the NuGet package has been installed, add the using HiQPdf.Chromium; statement at the top of your C# source file to include the HiQPdf.Chromium namespace in your application code and make the library API available.

C#
// Include the HiQPdf namespace at the top of your C# file
using HiQPdf.Chromium;

You are now ready to use the library to convert web pages and HTML content to PDF or images using the HiQPdf Chromium HTML to PDF Converter.

Convert an HTML String to PDF

With the code below, you can convert an HTML string to a PDF document in a memory buffer and then save the data from the buffer to a file.

C#
// Create the HTML to PDF converter object
HtmlToPdf converter = new HtmlToPdf();

// Convert the HTML code to memory
byte[] htmlToPdfData = converter.ConvertHtmlToMemory("<b>Hello World</b> from HiQPdf!", null);

// Save the PDF data to a file
System.IO.File.WriteAllBytes("html_to_memory.pdf", htmlToPdfData);

Convert a URL to PDF

With the code below, you can convert a URL to a PDF document in a memory buffer and then save the data from the buffer to a file. The URL can also be a local file path prefixed with the file:// URI scheme.

C#
// Create the HTML to PDF converter object
HtmlToPdf converter = new HtmlToPdf();

// Convert the HTML page from URL to memory
string urlToConvert = "http://www.hiqpdf.com";
byte[] urlToPdfData = converter.ConvertUrlToMemory(urlToConvert);

// Save the PDF data to a file
System.IO.File.WriteAllBytes("url_to_memory.pdf", urlToPdfData);

Convert an HTML String to PDF in ASP.NET

With the code below, you can convert an HTML string to a PDF document in a memory buffer in your ASP.NET Core applications, and then send it to the browser for download.

C#
// Create the HTML to PDF converter object
HtmlToPdf converter = new HtmlToPdf();

// Convert the HTML code to memory
byte[] htmlToPdfData = converter.ConvertHtmlToMemory("<b>Hello World</b> from HiQPdf!", null);

FileResult fileResult = new FileContentResult(htmlToPdfData, "application/pdf");
fileResult.FileDownloadName = "html_to_pdf.pdf";
return fileResult;

Convert a URL to PDF in ASP.NET

With the code below, you can convert a URL to a PDF document in a memory buffer in your ASP.NET Core applications, and then send it to the browser for download. The URL can also be a local file path prefixed with the file:// URI scheme.

C#
// Create the HTML to PDF converter object
HtmlToPdf converter = new HtmlToPdf();

// Convert the HTML code to memory
string urlToConvert = "http://www.hiqpdf.com";
byte[] urlToPdfData = converter.ConvertUrlToMemory(urlToConvert);

FileResult fileResult = new FileContentResult(urlToPdfData, "application/pdf");
fileResult.FileDownloadName = "url_to_pdf.pdf";
return fileResult;

Run Application

Everything should now be configured, and you can run your application. Alternatively, you can follow the same instructions from this document to build and publish our ASP.NET demo application on Windows.

See Also