HiQPdf Next Library for .NET

HiQPdf Next PDF Library for .NET Logo

With HiQPdf Next Library for .NET you can create, edit and merge PDF documents, convert HTML to PDF or to image, convert Word, Excel, RTF and Markdown to PDF, extract text and images from PDF, search text in PDF and convert PDF pages to images.

You can deploy the library on a variety of Windows and Linux platforms, including Azure App Service and Functions or Docker.

Download Now
Online Demo
Documentation

With HiQPdf Next Library for .NET you can create, edit and merge PDF documents, convert HTML to PDF or to image, convert Word, Excel, RTF and Markdown to PDF, extract text and images from PDF, search text in PDF and convert PDF pages to images.
The library has a modular structure, with separate NuGet packages for each major component. See below all HiQPdf Next components for more details.

Compatibility Platforms

HiQPdf Next for .NET can run on a variety of Windows and Linux platforms in web, console and desktop applications across all modern .NET platforms. The library components can be used in Azure App Service and Azure Functions environments on both Windows and Linux. Deployment to Docker Windows and Linux containers is also supported.
The .NET library targets .NET Standard 2.0, which makes it compatible with a wide range of .NET Core and .NET Framework applications.

Getting Started

The online documentation contains Getting Started guides for Windows, Linux, Azure App Service and Azure Functions, with detailed instructions for integrating the library into your application and complete C# examples for each important feature of the library.
You can see the current capabilities of the library by checking the online demo application for this library and the API reference in the online documentation.

Download Demo Application

You can also download a free trial package for .NET, which includes an ASP.NET demo application project with complete C# source code as a starting point for experimenting with your own usage scenarios.
Running the samples in the demo application that involve HTML to PDF conversion features on Linux platforms might require installing some dependency packages. The documentation includes an entire section dedicated to building, publishing and running the demo application on multiple platforms.

NuGet Packages

For Windows deployments, add a reference to the HiQPdf.Next.Windows NuGet package and for Linux deployments, add a reference to the HiQPdf.Next.Linux NuGet package. There is also a multiplatform metapackage that references both the Windows and Linux packages, HiQPdf.Next which is ideal when developing on one OS and deploying to multiple runtime environments.
These NuGet packages install all the library components. It is also possible to install only specific components. Please see each component page for details about which NuGet package should be installed for that component.

Installation

The HTML to PDF Converter component uses a platform specific runtime. On Windows platforms, the runtime generally does not require the installation of additional dependencies. On Linux platforms, installing some dependency packages might be necessary, depending on the exact Linux version you are using. In the online documentation in the Getting Started and Publish guides you can find instructions for installing Linux dependencies on a variety of Linux platforms.
The other components of the HiQPdf Next library do not generally require the installation of additional dependencies.

HiQPdf.Next Namespace

All components of the HiQPdf Next for .NET library share the same HiQPdf.Next namespace and can be used together in the same application. To use the library in your own code, add the using directive at the top of your C# source file, as shown below.
// Include the HiQPdf.Next namespace at the top of your C# file
using HiQPdf.Next;

HiQPdf Next for .NET Components

The library has a modular structure, with separate NuGet packages for each major component to prevent unnecessary files from being included in your applications. All components share the same HiQPdf.Next namespace and can be used together within the same project.
Core PDF API Logo

Core PDF API

The Core component provides the API for creating, manipulating and securing PDF documents programmatically. You can create PDFs by adding text, images and other elements, then apply encryption, digital signatures, permissions, headers, footers and stamps. You can find more details about this component in HiQPdf Next for .NET Core PDF API page.
HTML to PDF Logo

HTML to PDF

The HTML to PDF Converter is a core component of the HiQPdf Next Library for .NET, using a Chromium-based rendering engine that enables accurate conversion of complex web pages to PDF with the latest HTML, CSS and JavaScript standards and technologies. You can find more details about this component in HiQPdf Next HTML to PDF Converter for .NET page.
Word to PDF Logo

Word to PDF

The Word to PDF Converter is a component of the HiQPdf Next Library for .NET that enables accurate conversion of complex Word documents to PDF. You can enhance the generated PDF with a table of contents, headers, footers and stamps or apply security features. You can find more details about this component in HiQPdf Next Word to PDF Converter for .NET page.
Excel to PDF Logo

Excel to PDF

The Excel to PDF Converter is a component of the HiQPdf Next Library for .NET that enables accurate conversion of complex Excel documents to PDF. You can enhance the generated PDF with headers, footers and stamps or apply security features. You can find more details about this component in HiQPdf Next Excel to PDF Converter for .NET page.
RTF to PDF Logo

RTF to PDF

The RTF to PDF Converter is a component of the HiQPdf Next Library for .NET that enables accurate conversion of complex RTF documents to PDF. You can enhance the generated PDF with a table of contents, headers, footers and stamps or apply security features. You can find more details about this component in HiQPdf Next RTF to PDF Converter for .NET page.
Markdown to PDF Logo

Markdown to PDF

The Markdown to PDF Converter is a component of the HiQPdf Next Library for .NET that enables accurate conversion of complex MD documents to PDF. You can enhance the generated PDF with a table of contents, headers, footers and stamps or apply security features. You can find more details about this component in HiQPdf Next Markdown to PDF Converter for .NET page.
PDF to Text Logo

PDF to Text

The PDF to Text Converter is a component of the HiQPdf Next Library for .NET that enables text extraction from PDF documents in the original layout or optimized for reading, as well as text search in PDF that returns the exact positions of the matches. You can find more details about this component in HiQPdf Next PDF to Text for .NET page.
PDF to Image Logo

PDF to Image

The PDF to Image Converter is a component of the HiQPdf Next Library for .NET that enables the conversion of PDF pages to PNG images. You can control the color space, resolution and background transparency of the generated images. You can find more details about this component in HiQPdf Next PDF to Image for .NET page.
PDF Images Extractor Logo

PDF Images Extractor

The PDF Images Extractor is a component of the HiQPdf Next Library for .NET that enables the extraction of images from PDF files. The extracted images are in PNG format and preserve the transparency information available in the PDF. You can find more details about this component in HiQPdf Next PDF Images Extractor for .NET page.

Sample Code

After you add the reference to the NuGet package to your project, use the sample code below to convert a URL to a PDF document that you can either save to a file or send to the browser for download.
 // 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;

Features List

HiQPdf Next for .NET offers advanced options for creating, editing and merging PDF documents, converting HTML to PDF or to image, converting Word, Excel, RTF and Markdown to PDF, extracting text and images from PDF, searching text in PDF and converting PDF pages to images.

Convert HTML to PDF or to images, Convert Word, Excel, RTF and Markdown to PDF

Create complex PDF documents from HTML, Word, Excel, RTF and Markdown with an automatically generated table of contents. Add HTML headers, footers and stamps to the generated PDF documents.

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 fully supported by the converter in conformance with the latest standards and technologies.

Extract text and images from PDF, search text in PDF, convert PDF pages to images

HiQPdf Next for .NET allows you to extract text from PDF documents with the original layout or optimized for reading order, search text in PDF documents, convert PDF pages to PNG images, or extract the images from a PDF while preserving transparency.

Available on Both Windows and Linux Platforms

HiQPdf Next 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.

Create, edit and merge PDF documents

You can create PDF documents by adding text, images and other elements and then enhance them with features such as encryption, permissions, digital signatures, custom headers, footers and stamps.

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 10.0, 9.0, 8.0, 7.0, 6.0, .NET Standard 2.0 and .NET Framework 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 Next for .NET. Online documentation offers detailed usage instructions for Azure applications targeting both Windows and Linux.

NuGet Packages for Windows and Linux

HiQPdf Next 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 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 Next 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 complex HTML with CSS and JavaScript to PDF ...

Support for the latest HTML and JavaScript standards

Merge Multiple HTML documents in the same PDF document

Create headers and footers with page numbers using HTML

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 a table of contents from HTML heading tags

Create tagged PDFs to support the accessibility features

Convert the regions from the HTML page selected by a CSS selector

Exclude regions from the HTML page selected by a CSS selector

Retrieve HTML Element Positions in PDF

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

Trigger conversion automatically or manually from JavaScript ...

Control the PDF document display with PDF viewer preferences

Create secured and digitally signed PDF documents

Use HTTP GET or POST Requests to Access the HTML to Convert

Set HTTP headers when requesting the HTML page

Set cookies when requesting the HTML page

Convert HTML pages that require authentication

Convert HTML to JPEG, PNG and WEBP image formats

Convert Convert Word, Excel, RTF and Markdown to PDF

Extract text from PDF and search text in PDF

Extract images from PDF and convert PDF pages to images

Create, edit and merge PDF documents

Asynchronous Convert and Save Functions

HiQPdf Next for .NET - HTML to PDF C# Code Sample for ASP.NET Core

using System.ComponentModel.DataAnnotations;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Hosting;
using HiQPdf_Next_AspNetDemo.Models;

using HiQPdf.Next;

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

        // GET: ConvertHtmlToPdf
        public ActionResult Index()
        {
            var model = SetViewModel();
            return View(model);
        }

        [HttpPost]
        public ActionResult ConvertToPdf(ConvertHtmlToPdfViewModel model)
        {
            if (!ModelState.IsValid)
            {
                var errorMessage = ModelStateHelper.GetModelErrors(ModelState);
                throw new ValidationException(errorMessage);
            }

            // Replace the demo serial number with the serial number received upon purchase
            // to run the converter in licensed mode
            Licensing.SerialNumber = "YCgJMTAE-BiwJAhIB-EhlWTlBA-UEBRQFBA-U1FOUVJO-WVlZWQ==";

            // Create an HTML to PDF converter object with default settings
            HtmlToPdf htmlToPdfConverter = new HtmlToPdf();

            // Set browser width
            htmlToPdfConverter.BrowserWidth = model.BrowserWidth;

            // Set browser height if specified, otherwise use the default
            if (model.BrowserHeight.HasValue)
                htmlToPdfConverter.BrowserHeight = model.BrowserHeight.Value;

            // Set browser zoom
            htmlToPdfConverter.BrowserZoom = model.BrowserZoom;

            // Set an additional delay, in seconds, to wait for asynchronous content after the initial load
            // The default value is 0
            htmlToPdfConverter.WaitBeforeConvert = model.WaitTime;

            // Set the maximum time, in seconds, to wait for the HTML page to load
            // The default value is 120 seconds
            htmlToPdfConverter.HtmlLoadedTimeout = model.LoadHtmlTimeout;

            // Optionally load the lazy images
            htmlToPdfConverter.LoadLazyImages = model.LoadLazyImages;

            // Set the lazy images load mode
            htmlToPdfConverter.LazyImagesLoadMode = model.LazyImagesLoadMode == "Browser" ?
                LazyImagesLoadMode.Browser : LazyImagesLoadMode.Custom;

            // Set the media type used in @media rules when rendering HTML to PDF
            htmlToPdfConverter.MediaType = model.MediaType == "Print" ? "print" : "screen";

            // Automatically resize the PDF page width to match the BrowserWidth property
            // The default value is true
            htmlToPdfConverter.Document.AutoResizePdfPageWidth = model.AutoResizePdfPageWidth;

            // Set the PDF page size, which can be a predefined size like A4 or a custom size in points
            // The default is A4
            // Important Note: The PDF page width is automatically determined from the BrowserWidth
            // when the AutoResizePdfPageWidth property is true
            htmlToPdfConverter.Document.PageSize = GetSelectedPageSize(model.PageSize);

            // Set the PDF page orientation to Portrait or Landscape. The default is Portrait
            htmlToPdfConverter.Document.PageOrientation = GetSelectedPageOrientation(model.PageOrientation);

            // Set the PDF page margins in points. The default is 0
            htmlToPdfConverter.Document.Margins = new PdfMargins(
                        model.LeftMargin, model.RightMargin,
                        model.TopMargin, model.BottomMargin);

            // Set the document security
            htmlToPdfConverter.Document.Security.OpenPassword = model.OpenPassword;
            htmlToPdfConverter.Document.Security.AllowPrinting = model.AllowPrinting;

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

            if (model.UrlOrHtmlCode == "ConvertUrl")
            {
                // Convert URL to a PDF memory buffer
                string url = model.Url;

                pdfBuffer = htmlToPdfConverter.ConvertUrlToMemory(url);
            }
            else
            {
                // Convert HTML code
                string htmlCode = model.HtmlCode;
                string baseUrl = model.BaseUrl;

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

            FileResult fileResult = new FileContentResult(pdfBuffer, "application/pdf");
            if (!model.OpenInline)
                fileResult.FileDownloadName = "HtmlToPdf.pdf";

            return fileResult;
        }

        private PdfPageSize GetSelectedPageSize(string pageSize)
        {
            switch (pageSize)
            {
                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(string pageOrientation)
        {
            return pageOrientation == "Portrait" ?
                PdfPageOrientation.Portrait : PdfPageOrientation.Landscape;
        }

        private ConvertHtmlToPdfViewModel SetViewModel()
        {
            var model = new ConvertHtmlToPdfViewModel();
            return model;
        }
    }
}