HiQPdf Chromium Usage in Azure App Service and Azure Function Apps on Windows

HiQPdf Chromium for .NET offers you a modern, simple, fast, flexible and powerful tool to create complex and stylish PDF documents in Azure App Service and Azure Functions .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 rendering engine which can render all the modern HTML, CSS and JavaScript in conformance with the latest standards and technologies.

Compatible Platforms

HiQPdf Chromium HTML to PDF Converter for .NET can run in Azure App Service and Azure Functions Windows 64-bit applications without installing anything and without any prior configuration of the deployment environment. The steps necessary to use the library in your own Azure App Service and Azure Function applications are detailed below.

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

NuGet Package Installation

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, at the top of your C# source file add the using HiQPdf.Chromium; statement to include the HiQPdf.Chromium namespace in your application code and to make the library API available to your application.

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

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

Convert a HTML string to PDF

With the code below you can convert a HTML string to a PDF document in a memory buffer and then save the data from buffer into 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);

Convert an URL to PDF

With the code below you can convert an URL to a PDF document in a memory buffer and then save the data from buffer into a file. The URL can also be a local file path prefixed by 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);

Convert a HTML string to PDF in ASP.NET

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

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 an URL to PDF in ASP.NET

With the code below you can convert in your ASP.NET Core applications an URL to a PDF document in a memory buffer and then send it for download to browser. The URL can also be a local file path prefixed by 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;

Publish Your Application in Azure App Service on Windows

Uncheck the Deploy as ZIP package option when you create the publish profile in Visual Studio.

The minimum supported hosting plan size is B1 (1 core, 1.75GB). The recommended minimum hosting plan size is B2 (2 cores, 3.5 GB RAM) or a higher plan. The Free and Shared plans are not suitable for running the converter.

After the profile was created, before starting the publishing, select Portable as Target Runtime.

Publish the application in Azure App Service for Windows.

Publish Your Azure Function App on Windows

Uncheck the Run from package file option when you create the publish profile in Visual Studio.

Select the App service plan or Premium for Plan Type option in publish profile creation wizard. The Consumption plan is not suitable for running the converter.

The minimum supported hosting plan size is B1 (1 core, 1.75GB). The recommended minimum hosting plan size is B2 (2 cores, 3.5 GB RAM) or a higher plan. The Free and Shared plans are not suitable for running the converter.

After the profile was created, before starting the publishing, select Portable as Target Runtime.

Publish the Azure Function application for Windows.

Run Application

Everything should have been configured at this point and now you can run your application. Alternatively, you can follow the same instructions from this document to build and publish in Azure App Service for Windows our demo application for ASP.NET.

See Also