Create Word (DOCX) or PDF file on Azure

GemBox.Document is a standalone .NET component that's ideal for web applications because of its fast performance and thread safety when working with multiple DocumentModel objects.

GemBox.Document can be used on various platforms including Azure Functions and Azure App Services.

Azure Functions

To create an Azure function, search for "Azure Functions" in a new project dialog.

Screenshot of Visual Studio project type selection
Screenshot of Visual Studio project type selection

To avoid any potential issues with GemBox.Document, we recommend using the newer versions of Azure Functions (v3 or above). The following is an Azure function project file:

<Project Sdk="Microsoft.NET.Sdk">
    <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="4.1.3" />
    <PackageReference Include="GemBox.Document" Version="*" />
    <PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="6.0.0" />
    <None Update="host.json">
    <None Update="local.settings.json">

Note that saving to XPS and image formats (like PNG and JPG) currently works only on Azure Functions that target .NET Framework.

The following example shows how you can create a Word document using GemBox.Document in an Azure Function.

Generated Word document (DOCX format) from Azure Functions
Screenshot of Word file created with Azure function
using System.IO;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
using GemBox.Document;

public static class GemBoxFunction
    public static async Task<IActionResult> Run(
        [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = null)] HttpRequest req,
        ILogger log)
        // If using the Professional version, put your serial key below.

        DocumentModel document = new DocumentModel();

        Section section = new Section(document);

        Paragraph paragraph = new Paragraph(document);

        Run run = new Run(document, "Hello World!");

        var fileName = "Output.docx";
        var options = SaveOptions.DocxDefault;

        using (var stream = new MemoryStream())
            document.Save(stream, options);
            return new FileContentResult(stream.ToArray(), options.ContentType) { FileDownloadName = fileName };
Imports System.IO
Imports Microsoft.AspNetCore.Mvc
Imports Microsoft.Azure.WebJobs
Imports Microsoft.Azure.WebJobs.Extensions.Http
Imports Microsoft.AspNetCore.Http
Imports Microsoft.Extensions.Logging
Imports GemBox.Document

Module GemBoxFunction
    Async Function Run(
                       <HttpTrigger(AuthorizationLevel.Anonymous, "get", Route := Nothing)> req As HttpRequest,
                       log As ILogger) as Task(Of IActionResult)

        ' If using the Professional version, put your serial key below.

        Dim document As New DocumentModel()

        Dim section As New Section(document)

        Dim paragraph As New Paragraph(document)

        Dim inline As New Run(document, "Hello World!")

        Dim fileName = "Output.docx"
        Dim options = SaveOptions.DocxDefault

        Using stream As New MemoryStream()
            document.Save(stream, options)
            Return New FileContentResult(stream.ToArray(), options.ContentType) With { .FileDownloadName = fileName }
        End Using

    End Function
End Module

Azure App Services

App Service is a fully managed platform for building, deploying and scaling web apps. GemBox.Document can be used from applications that run on an App Service.

To build an ASP.NET Core application, check out our ASP.NET Core example.

To publish an application to Azure App service you need to:

1. Pick Azure as publish target.

Screenshot of Visual Studio target selection
Screenshot of Visual Studio target selection

2. Pick Azure App Service as a specific target.

Screenshot of Visual Studio specific target selection
Screenshot of Visual Studio specific target selection

3. Specify existing App Service or create a new one.

Screenshot of Visual Studio specific App Service selection
Screenshot of Visual Studio specific App Service selection

Limitations on App Services

You can use the full functionality of GemBox.Document on Azure Virtual Machine, Azure Cloud Services, and Azure Functions.

But for App Services, there are few rendering limitations:

These features currently have WPF dependencies which means they require a .NET Windows Desktop Runtime. However, we do have plans for providing cross-platform support for them in future releases.

See also

Next steps

GemBox.Document is a .NET component that enables you to read, write, edit, convert, and print document files from your .NET applications using one simple API. How about testing it today?

Download Buy