HiQPdf Chromium HTML to PDF Converter for .NET

HiQPdf Chromium HTML to PDF Converter for .NET Core

HiQPdf Chromium for .NET integrates a new rendering engine, enabling the accurate conversion of complex web pages to PDF using the latest HTML, CSS, and JavaScript standards and technologies.

You can deploy your .NET applications using this library on various Windows and Linux platforms, including the popular Azure App Service and Azure Functions platforms.

Download Now
Online Demo
Documentation

With the new HiQPdf Chromium HTML to PDF Converter for .NET you can now convert the most sophisticated HTML pages to PDF without losing formatting on Windows and Linux platforms. The converter can also be used without restrictions in Azure App Service and Azure Functions environments, both on Windows and Linux.
The .NET library targets .NET Standard 2.0, which makes it compatible with a wide range of .NET Core and .NET Framework applications. The .NET library is the same for Windows and Linux, but there are different native Chromium runtimes for the two platforms. The .NET library and the native runtimes are bundled and distributed as NuGet packages, which makes the installation and deployment extremely easy.
Getting Started
The online documentation contains Getting Started guides for Windows, Linux, Azure App Service and Azure Functions with detailed instructions for software integration in your application and complete C# examples for each important feature of the library.
HiQPdf Chromium Library for .NET inherited most of the API from the classic HiQPdf Library for .NET, but it also comes with some specific changes necessary to naturally adapt to the capabilities of the new rendering engine. You can see the current capabilities of the library by checking the online demo application for this new library and the API reference the online documentation.
You can also download a free trial package for .NET, which contains the Visual Studio project for the ASP.NET demo application with complete C# source code. On Windows platforms you can simply build and run the application from Visual Studio. Running the demo application on Linux requires following some steps that are described in detail in the documentation and also involve installing some dependency packages. After the Linux environment is prepared, you can publish the application on the Linux machine.
Instead of using our demo application, you can create your own ASP.NET project for .NET Core in Visual Studio. For Windows deployments it is not necessary to have any special setup and you can add a reference to HiQPdf.Chromium.Windows NuGet Package. If you want to publish your application on Linux, you should first follow the steps from documentation to configure the Linux machine for running the application and then add a reference to HiQPdf.Chromium.Linux NuGet Package. Use the simple code below to convert an URL to a PDF document you can save into a file or send it for download in browser.
 // 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;
HiQPdf Chromium for .NET offers advanced options for converting HTML to PDF and HTML to images. The library is more than just a HTML to PDF converter. It can also be used to automatically generate the PDF document outline with bookmarks, set the security permissions, password protect and digitally sign the generated PDF document.
Support for Cutting-Edge HTML, CSS and JavaScript Features
Using Chromium as the rendering engine ensures that the latest modern HTML, CSS, and JavaScript features are supported by the converter in conformance with the latest standards and technologies.
Available on Both Windows and Linux Platforms
HiQPdf Chromium for .NET can run on both Windows 64-bit and Linux 64-bit platforms. There are different NuGet packages for Windows and Linux, including the same .NET library but with different native runtimes. For Windows, the minimum required version is Windows 10 or Windows Server 2016.
Built for .NET Standard 2.0 for Maximum Compatibility
The .NET library targets .NET Standard 2.0, making it compatible with a wide range of .NET Core and .NET Framework applications. It is compatible with .NET Core 8.0, 7.0, 6.0, 5.0 and .NET Framework versions from 4.6.2 to 4.8.1.
Fully Compatible with Azure App Service and Azure Functions on Both Windows and Linux
The converter can run without restrictions in your Azure App Service and Azure Functions .NET Core applications targeting both Windows and Linux platforms. Web fonts and other features are fully supported by HiQPdf Chromium for .NET. Online documentation offers detailed usage instructions for Azure applications targeting both Windows and Linux.
NuGet Packages for Windows and Linux
HiQPdf Chromium for .NET is delivered as NuGet packages for Windows and Linux. The packages include the .NET Standard 2.0 library, the same for both platforms, and the specific native runtime for each platform.
ASP.NET Core Demo Application with C# Code for All Features
The zip package that can be downloaded from the website contains the Visual Studio project for the ASP.NET Core demo application with C# sample code for all major library features.
Simple and Flexible Licensing with a Single License for All Libraries
The license for HiQPdf Chromium for .NET works with both the classic HiQPdf Library for .NET and the multi-platform client-server solution. There are no additional runtime or deployment costs charged for using our software component in your applications.

Convert Convert complex HTML with CSS and JavaScript to PDF ...

Support for the latest HTML and JavaScript technologies and standards

Create headers and footers with page numbers from HTML templates

Automatically repeat HTML tables headers and footers in PDF pages

Control PDF page breaks with CSS attributes in HTML

Create PDF document outline from HTML heading tags

Create tagged PDFs to support the accessibility features ...

Trigger conversion automatically or manually from JavaScript code

Control the media type to render for screen or for print mode

Control the PDF document display with PDF viewer preferences

Create secured and digitally signed PDF documents

Convert HTML to JPEG, PNG and WEBP image formats

HiQPdf Chromium for .NET - HTML to PDF C# Code Sample for ASP.NET Core
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Hosting;

using HiQPdf.Chromium;

namespace HiQPdf_Chrome_AspNetDemo.Controllers
{
    public class ConvertHtmlToPdfController : Controller
    {
        IFormCollection m_formCollection;
        IWebHostEnvironment m_hostingEnvironment;
        public ConvertHtmlToPdfController(IWebHostEnvironment hostingEnvironment)
        {
            m_hostingEnvironment = hostingEnvironment;
        }

        // GET: ConvertHtmlToPdf
        public ActionResult Index()
        {
            return View();
        }

        [HttpPost]
        public ActionResult ConvertToPdf(IFormCollection collection)
        {
            m_formCollection = collection;

            // create the HTML to PDF converter
            HtmlToPdf htmlToPdfConverter = new HtmlToPdf();

            // set a demo serial number
            htmlToPdfConverter.SerialNumber = "YCgJMTAE-BiwJAhIB-EhlWTlBA-UEBRQFBA-U1FOUVJO-WVlZWQ==";

            // set browser width
            htmlToPdfConverter.BrowserWidth = int.Parse(collection["textBoxBrowserWidth"]);

            // set browser height if specified, otherwise use the default
            if (collection["textBoxBrowserHeight"][0].Length > 0)
                htmlToPdfConverter.BrowserHeight = int.Parse(collection["textBoxBrowserHeight"]);

            // set browser zoom
            htmlToPdfConverter.BrowserZoom = int.Parse(collection["textBoxBrowserZoom"]);

            // auto resize the browser height based on HTML content size determined after initial loading
            htmlToPdfConverter.AutoResizeBrowserHeight = collection["checkBoxAutoResizeBrowserHeight"].Count > 0;

            // set wait time before starting conversion
            htmlToPdfConverter.WaitBeforeConvert = int.Parse(collection["textBoxWaitTime"]);

            // set HTML Load timeout
            htmlToPdfConverter.HtmlLoadedTimeout = int.Parse(collection["textBoxLoadHtmlTimeout"]);

            // set the selected media type
            htmlToPdfConverter.MediaType = collection["MediaType"] == "radioButtonPrintMediaType" ? "print" : "screen";

            // set PDF page size and orientation
            htmlToPdfConverter.Document.PageSize = GetSelectedPageSize();
            htmlToPdfConverter.Document.PageOrientation = GetSelectedPageOrientation();

            // set PDF page width auto resize to match the BrowserWidth
            htmlToPdfConverter.Document.AutoResizePdfPageWidth = collection["checkBoxAutoResizePdfPageWidth"].Count > 0;

            // set PDF page margins
            // set PDF page margins
            htmlToPdfConverter.Document.Margins = new PdfMargins(
                        int.Parse(collection["textBoxLeftMargin"]), int.Parse(collection["textBoxRightMargin"]),
                        int.Parse(collection["textBoxTopMargin"]), int.Parse(collection["textBoxBottomMargin"]));

            // set the document security
            htmlToPdfConverter.Document.Security.OpenPassword = collection["textBoxOpenPassword"];
            htmlToPdfConverter.Document.Security.AllowPrinting = collection["checkBoxAllowPrinting"].Count > 0;

            // convert HTML to PDF
            byte[] pdfBuffer = null;

            if (collection["UrlOrHtmlCode"] == "radioButtonConvertUrl")
            {
                // convert URL to a PDF memory buffer
                string url = collection["textBoxUrl"];

                pdfBuffer = htmlToPdfConverter.ConvertUrlToMemory(url);
            }
            else
            {
                // convert HTML code
                string htmlCode = collection["textBoxHtmlCode"];
                string baseUrl = collection["textBoxBaseUrl"];

                // convert HTML code to a PDF memory buffer
                pdfBuffer = htmlToPdfConverter.ConvertHtmlToMemory(htmlCode, baseUrl);
            }

            FileResult fileResult = new FileContentResult(pdfBuffer, "application/pdf");
            if (collection["checkBoxOpenInline"].Count == 0)
                fileResult.FileDownloadName = "HtmlToPdf.pdf";

            return fileResult;
        }

        private PdfPageSize GetSelectedPageSize()
        {
            switch (m_formCollection["dropDownListPageSizes"])
            {
                case "A0":
                    return PdfPageSize.A0;
                case "A1":
                    return PdfPageSize.A1;
                case "A10":
                    return PdfPageSize.A10;
                case "A2":
                    return PdfPageSize.A2;
                case "A3":
                    return PdfPageSize.A3;
                case "A4":
                    return PdfPageSize.A4;
                case "A5":
                    return PdfPageSize.A5;
                case "A6":
                    return PdfPageSize.A6;
                case "A7":
                    return PdfPageSize.A7;
                case "A8":
                    return PdfPageSize.A8;
                case "A9":
                    return PdfPageSize.A9;
                case "ArchA":
                    return PdfPageSize.ArchA;
                case "ArchB":
                    return PdfPageSize.ArchB;
                case "ArchC":
                    return PdfPageSize.ArchC;
                case "ArchD":
                    return PdfPageSize.ArchD;
                case "ArchE":
                    return PdfPageSize.ArchE;
                case "B0":
                    return PdfPageSize.B0;
                case "B1":
                    return PdfPageSize.B1;
                case "B2":
                    return PdfPageSize.B2;
                case "B3":
                    return PdfPageSize.B3;
                case "B4":
                    return PdfPageSize.B4;
                case "B5":
                    return PdfPageSize.B5;
                case "Flsa":
                    return PdfPageSize.Flsa;
                case "HalfLetter":
                    return PdfPageSize.HalfLetter;
                case "Ledger":
                    return PdfPageSize.Ledger;
                case "Legal":
                    return PdfPageSize.Legal;
                case "Letter":
                    return PdfPageSize.Letter;
                case "Letter11x17":
                    return PdfPageSize.Letter11x17;
                case "Note":
                    return PdfPageSize.Note;
                default:
                    return PdfPageSize.A4;
            }
        }

        private PdfPageOrientation GetSelectedPageOrientation()
        {
            return m_formCollection["dropDownListPageOrientations"] == "Portrait" ?
                PdfPageOrientation.Portrait : PdfPageOrientation.Landscape;
        }
    }
}