HiQPdf Chromium Library for .NET Core

HiQPdf Chromium Logo 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.

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.

list itemSupport 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.

list item 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.

list item 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.

list itemFully 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.

list itemNuGet 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.

list itemASP.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.

DemoDemo DownloadDownload ContactPurchase ContactHelp

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.

HQPdf HTML to PDF Detailed FeaturesDetailed Features

Below you can find a detailed description of the most important features of the HiQPdf Chromium for .NET, each feature having also a corresponding sample in the online demo.

  • Convert complex HTML with CSS and JavaScript to PDF - Quickly and accurately convert complex HTML documents with CSS, JavaScript, SVG and Web Fonts to PDF or Image.
  • Support for the latest HTML and JavaScript technologies and standards - Using Chromium as rendering engine ensures that the latest modern HTML, CSS and JavaScript features are supported by converter in conformance with the latest standards and technologies.
  • Create headers and footers with page numbers from HTML templates - HiQPdf Chromium for .NET allows you to control the headers and footers of the generated PDF document. You can add in the header and footer any valid HTML markup and elements with special CSS class names to generate page numbering and other dynamic content.
  • Automatically repeat HTML tables headers and footers in PDF pages - The converter will automatically repeat the 'thead' and the 'tfoot' of a HTML table on each PDF page where the table is laid out when converting for print media type. By default the converter renders for screen media type and you can enable the HTML table header and footer repeating in PDF pages by changing the media type to print.
  • Control PDF page breaks with CSS attributes in HTML - The page breaks in the generated PDF document can be controlled using the following CSS properties. 'page-break-before : always' style forces a page break in PDF right before the box where the element is rendered, 'page-break-after : always' style forces a page break in PDF right after the box where the element is rendered, 'page-break-inside : avoid' style will make the converter to generate the PDF such that the element with this style is not cut between PDF pages if possible.
  • Create PDF document outline from HTML heading tags - If your HTML is structured using the heading tags H1 to H6 then you can use the special option 'PdfDocumentControl.GenerateDocumentOutline' to automatically create a hierarchy of outlines based on document structure.
  • Create tagged PDFs to support the accessibility features - You can use the option 'PdfDocumentControl.GenerateTaggedPdf' to automatically create a tagged PDF which has a special logical structure which enables various accessibility features in PDF viewers.
  • Trigger conversion automatically or manually from JavaScript code - The converter offers two conversion triggering modes: Auto and Manual. The triggering mode is controlled by the 'HtmlToPdf.TriggerMode' property of the converter.
  • Control the media type to render for screen or for print mode - Using CSS media types a HTML document can have one layout for screen and a different layout for print. The @media rule allows different styles for different media types in the same HTML document.
  • Control the PDF document display with PDF viewer preferences - HiQPdf HTML to PDF Converter for .NET offers the possibility to control how the generated PDF document is displayed in a PDF viewer like Adobe Reader. There are options to hide the PDF viewer menu and toolbar, to initially display the Bookmarks, Thumbnails or Attachments panel, to display the PDF pages in one or two columns.
  • Create secured and digitally signed PDF documents - HiQPdf Chromium for .NET offers you multiple possibilities to secure and to set the permitted operations on the generated PDF document. You can password protect the PDF document with separate passwords to open the PDF document and to edit the permissions. It is also possible add digital signatures to the generated PDF document using a certificate with private and public keys.
  • Convert HTML to JPEG, PNG and WEBP image formats - The HTML to Image converter allows you to quickly create screenshots of the HTML documents. The image can be saved in various formats like PNG, JPEG or WEBP.

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;
        }
    }
}