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.

WarningNote: 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);
System.AppContext.SetSwitch("System.Drawing.EnableUnixSupport", True)
$vbLabelText   $csharpLabel

Azure Function Code Example

This example is converting HTML to PDF and 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}");
    }
}
<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 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...")
		Dim renderer As New ChromePdfRenderer()
		' Render PDF from a URL
		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")
		Return New OkObjectResult($"Error while rendering PDF: {e}")
	End Try
End Function
$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

How can I host a PDF generating library on Azure?

You can host a PDF generating library like IronPDF on Azure by setting up an Azure Function or an MVC website. Ensure you have the necessary packages installed from NuGet and configure your environment according to the library's requirements.

Which Azure environments are compatible with a PDF library?

IronPDF is compatible with multiple Azure environments, including MVC websites and Azure Functions. It is designed to work seamlessly across different platforms provided by Azure.

What are the hosting requirements for a PDF library on Azure?

For optimal performance when using IronPDF on Azure, it is recommended to use at least the Azure Basic B1 hosting tier. This ensures sufficient resources for rendering PDFs efficiently.

How do I set up a PDF library for an Azure Function App on Linux?

To set up IronPDF for an Azure Function App on Linux, install the IronPdf.Slim package. Deploy your project as a ZIP file and ensure all configurations are set correctly for the Linux environment.

What configurations are needed for .NET 6 when using a PDF library on Azure?

When using IronPDF with .NET 6 on Azure, update your project settings to allow legacy API calls. Set Installation.LinuxAndDockerDependenciesAutoConfig=true and include necessary configurations in your project files.

Why is a Docker Container recommended for PDF rendering on Azure?

A Docker Container is recommended for PDF rendering on Azure because it provides a more controlled environment, supports better font rendering, and avoids limitations of shared hosting plans.

What can cause slow PDF rendering on Azure Free Tier?

PDF rendering is slow on Azure Free Tier due to limited computing resources. The process requires significant computational power, similar to rendering a web page, making higher-tier plans like B1 or Premium more suitable.

How can I troubleshoot a non-working Azure Function project with a PDF library?

If your Azure Function project with IronPDF is not functioning, check the CustomDeploymentDirectory property is set to '/tmp', and ensure all necessary packages and configurations are correctly installed and set.

What support options are available for deploying a PDF library on Azure?

For support with deploying IronPDF on Azure, consult the 'How to Make an Engineering Support Request for IronPDF' guide on the IronPDF website for detailed assistance.

Chaknith Bin
Software Engineer
Chaknith works on IronXL and IronBarcode. He has deep expertise in C# and .NET, helping improve the software and support customers. His insights from user interactions contribute to better products, documentation, and overall experience.