How to Run & Deploy IronPDF .NET on Azure Function

Azure 1 related to 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
Note: 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>
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
XML
  1. 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);
System.AppContext.SetSwitch("System.Drawing.EnableUnixSupport", true);
$vbLabelText   $csharpLabel

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 logging
    IronPdf.Logging.Logger.LoggingMode = IronPdf.Logging.Logger.LoggingModes.Custom;
    IronPdf.Logging.Logger.CustomLogger = log;

    // Configure IronPdf settings
    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 from a URL
        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");
        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 logging
    IronPdf.Logging.Logger.LoggingMode = IronPdf.Logging.Logger.LoggingModes.Custom;
    IronPdf.Logging.Logger.CustomLogger = log;

    // Configure IronPdf settings
    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 from a URL
        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");
        return new OkObjectResult($"Error while rendering PDF: {e}");
    }
}
$vbLabelText   $csharpLabel

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

Frequently Asked Questions

Can IronPDF be used on Azure?

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

What is the recommended Azure Function App environment for IronPDF?

The Azure Function App Container is recommended for deploying IronPDF as it provides an isolated environment and involves minimal hassle.

Which hosting tier is required for using IronPDF on Azure?

Azure Basic B1 is the minimum hosting level required for IronPDF's rendering needs. For high throughput systems, a higher tier may be necessary.

What package should be installed for IronPDF on a Linux Azure Function App?

For a Linux Azure Function App, the IronPdf.Slim package should be installed, as the project is deployed as a ZIP file by default.

How do I configure IronPDF for .NET 6 on Azure?

To configure IronPDF for .NET 6, you need to adjust your project settings to allow legacy API calls by setting Installation.LinuxAndDockerDependenciesAutoConfig=true and updating your project files with specific configurations.

Is SVG font rendering supported on Azure shared hosting plans?

No, SVG font rendering is not supported on Azure's cheaper shared hosting plans due to security restrictions. A Windows or Linux Docker Container is recommended for better font rendering.

Why is Azure Free Tier hosting not recommended for PDF rendering?

Azure Free Tier hosting is slow for PDF rendering because the process involves significant computing work similar to rendering a web page on a desktop. A B1 hosting or Premium plan is recommended for better performance.

What should I do if my Azure Function project with IronPDF does not work?

If your project does not work as expected, ensure the CustomDeploymentDirectory property is set to '/tmp' and check that all necessary packages and configurations are properly installed and set.

How can I request engineering support for IronPDF?

To request engineering support for IronPDF, refer to the 'How to Make an Engineering Support Request for IronPDF' guide available on the IronPDF website.