How to Run & Deploy IronPDF .NET on Azure Function

Yes. IronPDF can be used to generate, manipulate, and read PDF documents on Azure. IronPDF has been thoroughly tested on multiple Azure platforms including MVC websites, Azure Functions, and many more.


How to Tutorial

Install IronPdf Package

Azure Function Apps have three distinct environments: Linux, Windows, and Container. This article explains how to set up IronPdf in all three environments. Among these, Azure Function App Container is recommended because it provides an isolated environment. To begin, let’s select the appropriate package to install.

Azure Function App Container

Azure Function App Container involves minimal hassle, making it the recommended way to deploy IronPdf.

Install-Package IronPdf.Linux

Configure Docker File

Configure the Docker file based on the Linux distribution you are using. Please refer to this article for detailed instructions.

Azure Function App(Windows)

To use the standard IronPdf package, ensure the Run from package file option is unchecked. Enabling this option deploys the project as a ZIP file, which interferes with IronPdf's file configuration. If you prefer to enable the Run from package file option, install the IronPdf.Slim package instead.

Install-Package IronPdf
Azure Package File related to Azure Function App(Windows)

Azure Function App(Linux)

For Azure Function App (Linux), the project is deployed as a ZIP file by default, and this behavior cannot be disabled. This is similar to enabling the Run from package file option on Azure Function App (Windows).

Install-Package IronPdf.Slim

Select Correct Azure Options

Choosing the correct hosting Tier

Azure Basic B1 is the minimum hosting level required for our end users' rendering needs. If you are creating a high throughput system, this may need to be upgraded.

Before proceeding
Failure to select a Plan Type of App service plan may result in IronPdf failing to render PDF documents.

Choosing the correct hosting level Azure Tier

Configuration for .NET 6

Microsoft recently removed imaging libraries from .NET 6+, breaking many legacy APIs. As such, it is necessary to configure your project to still allow these legacy API calls.

  1. On Linux, set Installation.LinuxAndDockerDependenciesAutoConfig=true; to ensure libgdiplus is installed on the machine
  2. Add the following to the .csproj file for your .NET 6 project: <GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
  3. Create a file in your project called runtimeconfig.template.json and populate it with the following:
{
      "configProperties": {
         "System.Drawing.EnableUnixSupport": true
      }
}
  1. Finally, add the following line to the beginning of your program: System.AppContext.SetSwitch("System.Drawing.EnableUnixSupport", true);

Azure Function Code Example

This example automatically outputs log entries to the built-in Azure logger (see ILogger log).

[FunctionName("PrintPdf")]
public static async Task<IActionResult> Run(
    [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req,
    ILogger log, ExecutionContext context)
{
    log.LogInformation("Entered PrintPdf API function...");

    // Apply license key
    IronPdf.License.LicenseKey = "IRONPDF-MYLICENSE-KEY-1EF01";

    // Enable log
    IronPdf.Logging.Logger.LoggingMode = IronPdf.Logging.Logger.LoggingModes.Custom;
    IronPdf.Logging.Logger.CustomLogger = log;

    // Configure IronPdf
    IronPdf.Installation.LinuxAndDockerDependenciesAutoConfig = true;
    IronPdf.Installation.AutomaticallyDownloadNativeBinaries = true;
    IronPdf.Installation.ChromeGpuMode = IronPdf.Engines.Chrome.ChromeGpuModes.Disabled;
    IronPdf.Installation.CustomDeploymentDirectory = "/tmp";

    try
    {
        log.LogInformation("About to render pdf...");
        ChromePdfRenderer renderer = new ChromePdfRenderer();
        // Render PDF
        var pdf = renderer.RenderUrlAsPdf("https://www.google.com/");
        log.LogInformation("finished rendering pdf...");
        return new FileContentResult(pdf.BinaryData, "application/pdf") { FileDownloadName = "google.pdf" };
    }
    catch (Exception e)
    {
        log.LogError(e, "Error while rendering pdf", e);
        return new OkObjectResult($"Error while rendering pdf: {e}");
    }
}
[FunctionName("PrintPdf")]
public static async Task<IActionResult> Run(
    [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req,
    ILogger log, ExecutionContext context)
{
    log.LogInformation("Entered PrintPdf API function...");

    // Apply license key
    IronPdf.License.LicenseKey = "IRONPDF-MYLICENSE-KEY-1EF01";

    // Enable log
    IronPdf.Logging.Logger.LoggingMode = IronPdf.Logging.Logger.LoggingModes.Custom;
    IronPdf.Logging.Logger.CustomLogger = log;

    // Configure IronPdf
    IronPdf.Installation.LinuxAndDockerDependenciesAutoConfig = true;
    IronPdf.Installation.AutomaticallyDownloadNativeBinaries = true;
    IronPdf.Installation.ChromeGpuMode = IronPdf.Engines.Chrome.ChromeGpuModes.Disabled;
    IronPdf.Installation.CustomDeploymentDirectory = "/tmp";

    try
    {
        log.LogInformation("About to render pdf...");
        ChromePdfRenderer renderer = new ChromePdfRenderer();
        // Render PDF
        var pdf = renderer.RenderUrlAsPdf("https://www.google.com/");
        log.LogInformation("finished rendering pdf...");
        return new FileContentResult(pdf.BinaryData, "application/pdf") { FileDownloadName = "google.pdf" };
    }
    catch (Exception e)
    {
        log.LogError(e, "Error while rendering pdf", e);
        return new OkObjectResult($"Error while rendering pdf: {e}");
    }
}
<FunctionName("PrintPdf")>
Public Shared Async Function Run(<HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route := Nothing)> ByVal req As HttpRequest, ByVal log As ILogger, ByVal context As ExecutionContext) As Task(Of IActionResult)
	log.LogInformation("Entered PrintPdf API function...")

	' Apply license key
	IronPdf.License.LicenseKey = "IRONPDF-MYLICENSE-KEY-1EF01"

	' Enable log
	IronPdf.Logging.Logger.LoggingMode = IronPdf.Logging.Logger.LoggingModes.Custom
	IronPdf.Logging.Logger.CustomLogger = log

	' Configure IronPdf
	IronPdf.Installation.LinuxAndDockerDependenciesAutoConfig = True
	IronPdf.Installation.AutomaticallyDownloadNativeBinaries = True
	IronPdf.Installation.ChromeGpuMode = IronPdf.Engines.Chrome.ChromeGpuModes.Disabled
	IronPdf.Installation.CustomDeploymentDirectory = "/tmp"

	Try
		log.LogInformation("About to render pdf...")
		Dim renderer As New ChromePdfRenderer()
		' Render PDF
		Dim pdf = renderer.RenderUrlAsPdf("https://www.google.com/")
		log.LogInformation("finished rendering pdf...")
		Return New FileContentResult(pdf.BinaryData, "application/pdf") With {.FileDownloadName = "google.pdf"}
	Catch e As Exception
		log.LogError(e, "Error while rendering pdf", e)
		Return New OkObjectResult($"Error while rendering pdf: {e}")
	End Try
End Function
VB   C#

Creating a project using the Azure Function template in Visual Studio may result in slightly different code. Due to these differences, even with the same package installed, one project might work while the other does not. If this occurs, please set the CustomDeploymentDirectory property to "/tmp".

Understand Each Installation Configuration

  • LinuxAndDockerDependenciesAutoConfig: This setting checks and attempts to download all necessary dependencies for the Chrome Engine. It is required when using non-GUI systems, such as Linux. In container systems, the dependencies are usually listed in the Dockerfile; therefore, you can set this to false.
  • AutomaticallyDownloadNativeBinaries: This option downloads the native Chrome binary at runtime. It is required when using the IronPdf.Slim package.
  • CustomDeploymentDirectory: This setting is required for systems with limited write access.

Known Issues

SVG fonts rendering is not available on shared hosting plans

One limitation we have found is that the Azure hosting platform does not support servers loading SVG fonts, such as Google Fonts, in their cheaper shared web-app tiers. This is because these shared hosting platforms are not allowed to access windows GDI+ graphics objects for security reasons.

We recommend using a Windows or Linux Docker Container or perhaps a VPS on Azure to navigate this issue where the best font rendering is required.

Azure free tier hosting is slow

Azure free and shared tiers, and the consumption plan, are not suitable for PDF rendering. We recommend Azure B1 hosting/Premium plan, which is what we use ourselves. The process of HTML to PDF is significant 'work' for any computer - similar to opening and rendering a web page on your own machine. A real browser engine is used, hence we need to provision accordingly and expect similar render times to a desktop machine of similar power.

Creating an Engineering Support Request Ticket

In order to create a request ticket refer to the 'How to Make an Engineering Support Request for IronPDF' guide