How To Run IronWord with .NET on Azure

This article was translated from English: Does it need improvement?
Translated
View the article in English

IronWord is a powerful .NET library for creating, editing, and reading Word documents programmatically. It works seamlessly on various Azure services including Azure App Services, Azure Functions, and Azure Container Instances.

Installing IronWord

Begin by installing the IronWord NuGet package from the official NuGet repository:

Install-Package IronWord

Hosting Considerations for Azure

Choosing the Right Azure Service Tier

IronWord performs best on Azure service plans that provide consistent compute availability. For most small to medium use cases, the Basic (B1) App Service Plan is sufficient. If your application processes a high volume of Word documents or performs complex formatting tasks, consider upgrading to Standard (S1) or higher tiers to avoid performance bottlenecks.

Supported .NET Runtimes and Compatibility

IronWord works out of the box with the following frameworks commonly used in Azure-hosted solutions:

  • .NET 6+ (LTS recommended)
  • .NET Core 3.1
  • .NET Standard 2.1

This gives you flexibility to deploy IronWord across various Azure services like App Services, Azure Functions, and Docker containers without worrying about compatibility.

Deploying in Docker on Azure

Containerized Deployment with IronWord

If you're looking for maximum control over your runtime environment, consider deploying IronWord inside a Docker container on Azure Container Instances (ACI) or Azure Kubernetes Service (AKS). This allows you to:

  • Pre-load templates or static resources
  • Configure document processing settings
  • Fine-tune performance at the OS level

To get started, use a base image such as mcr.microsoft.com/dotnet/aspnet:6.0 or 7.0 and add IronWord via NuGet or manual DLL inclusion.

Serverless with Azure Functions

Using IronWord in Azure Functions

IronWord is fully compatible with Azure Functions v4 running on .NET 6 or higher. This enables lightweight, event-driven document generation—perfect for scenarios like:

  • On-demand report creation via HTTP
  • Generating Word documents from form submissions
  • Converting structured data into .docx format

Azure Function Example: Generate Word Document on Request

Below is a real-world example of an Azure Function that creates and returns a Word document in response to an HTTP request:

using System.Net;
using System.Net.Http;
using Microsoft.AspNetCore.Http;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.Extensions.Logging;
using System.Net.Http.Headers;
using IronWord;
using IronWord.Models;
using System.IO;
using System.Threading.Tasks;

public static class WordFunction
{
    [FunctionName("GenerateWordDoc")]
    public static HttpResponseMessage Run(
        [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req,
        ILogger log)
    {
        log.LogInformation("Processing request to generate Word document...");

        // Set your IronWord license key
        IronWord.License.LicenseKey = "YOUR-LICENSE-KEY";

        // Create and populate Word document
        var doc = new WordDocument();
        Paragraph para1 = new Paragraph(new TextContent("This Word document was generated by IronWord in an Azure Function."));
        Paragraph para2 = new Paragraph(new TextContent($"Timestamp: {System.DateTime.UtcNow}"));
        doc.AddParagraph(para1);
        doc.AddParagraph(para2);

        // Save to temporary file
        string tempPath = Path.GetTempFileName().Replace(".tmp", ".docx");
        doc.SaveAs(tempPath);

        // Read the file bytes
        byte[] fileBytes = File.ReadAllBytes(tempPath);

        // Optionally delete the temp file
        File.Delete(tempPath);

        // Build the response with the document as an attachment
        var response = new HttpResponseMessage(HttpStatusCode.OK)
        {
            Content = new ByteArrayContent(fileBytes)
        };
        response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
        {
            FileName = $"IronWord_{System.DateTime.UtcNow:yyyyMMdd_HHmmss}.docx"
        };
        response.Content.Headers.ContentType = new MediaTypeHeaderValue(
            "application/vnd.openxmlformats-officedocument.wordprocessingml.document");

        return response;
    }
}
using System.Net;
using System.Net.Http;
using Microsoft.AspNetCore.Http;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.Extensions.Logging;
using System.Net.Http.Headers;
using IronWord;
using IronWord.Models;
using System.IO;
using System.Threading.Tasks;

public static class WordFunction
{
    [FunctionName("GenerateWordDoc")]
    public static HttpResponseMessage Run(
        [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req,
        ILogger log)
    {
        log.LogInformation("Processing request to generate Word document...");

        // Set your IronWord license key
        IronWord.License.LicenseKey = "YOUR-LICENSE-KEY";

        // Create and populate Word document
        var doc = new WordDocument();
        Paragraph para1 = new Paragraph(new TextContent("This Word document was generated by IronWord in an Azure Function."));
        Paragraph para2 = new Paragraph(new TextContent($"Timestamp: {System.DateTime.UtcNow}"));
        doc.AddParagraph(para1);
        doc.AddParagraph(para2);

        // Save to temporary file
        string tempPath = Path.GetTempFileName().Replace(".tmp", ".docx");
        doc.SaveAs(tempPath);

        // Read the file bytes
        byte[] fileBytes = File.ReadAllBytes(tempPath);

        // Optionally delete the temp file
        File.Delete(tempPath);

        // Build the response with the document as an attachment
        var response = new HttpResponseMessage(HttpStatusCode.OK)
        {
            Content = new ByteArrayContent(fileBytes)
        };
        response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
        {
            FileName = $"IronWord_{System.DateTime.UtcNow:yyyyMMdd_HHmmss}.docx"
        };
        response.Content.Headers.ContentType = new MediaTypeHeaderValue(
            "application/vnd.openxmlformats-officedocument.wordprocessingml.document");

        return response;
    }
}
Imports System
Imports System.Net
Imports System.Net.Http
Imports Microsoft.AspNetCore.Http
Imports Microsoft.Azure.WebJobs
Imports Microsoft.Azure.WebJobs.Extensions.Http
Imports Microsoft.Extensions.Logging
Imports System.Net.Http.Headers
Imports IronWord
Imports IronWord.Models
Imports System.IO
Imports System.Threading.Tasks

Public Module WordFunction
	<FunctionName("GenerateWordDoc")>
	Public Function Run(<HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route := Nothing)> ByVal req As HttpRequest, ByVal log As ILogger) As HttpResponseMessage
		log.LogInformation("Processing request to generate Word document...")

		' Set your IronWord license key
		IronWord.License.LicenseKey = "YOUR-LICENSE-KEY"

		' Create and populate Word document
		Dim doc = New WordDocument()
		Dim para1 As New Paragraph(New TextContent("This Word document was generated by IronWord in an Azure Function."))
		Dim para2 As New Paragraph(New TextContent($"Timestamp: {DateTime.UtcNow}"))
		doc.AddParagraph(para1)
		doc.AddParagraph(para2)

		' Save to temporary file
		Dim tempPath As String = Path.GetTempFileName().Replace(".tmp", ".docx")
		doc.SaveAs(tempPath)

		' Read the file bytes
		Dim fileBytes() As Byte = File.ReadAllBytes(tempPath)

		' Optionally delete the temp file
		File.Delete(tempPath)

		' Build the response with the document as an attachment
		Dim response = New HttpResponseMessage(HttpStatusCode.OK) With {.Content = New ByteArrayContent(fileBytes)}
		response.Content.Headers.ContentDisposition = New ContentDispositionHeaderValue("attachment") With {.FileName = $"IronWord_{DateTime.UtcNow:yyyyMMdd_HHmmss}.docx"}
		response.Content.Headers.ContentType = New MediaTypeHeaderValue("application/vnd.openxmlformats-officedocument.wordprocessingml.document")

		Return response
	End Function
End Module
$vbLabelText   $csharpLabel

Code Explanation:

  1. We define an Azure Function with the name "GenerateWordDoc".
  2. The function is triggered by an HTTP GET or POST request and logs a message when it begins processing.
  3. We specify the license key for IronWord by setting IronWord.License.LicenseKey (replace "YOUR-LICENSE-KEY" with your actual key).
  4. A new WordDocument is created using IronWord's API.
  5. Two paragraphs are added to the document — one with static text and another showing the current UTC timestamp.
  6. The document is saved to a temporary .docx file on the server using doc.SaveAs(tempPath).
  7. The saved file is read into a byte array using File.ReadAllBytes, preparing it for download.
  8. The temporary file is deleted immediately after reading to keep the system clean.
  9. An HttpResponseMessage is built, containing the document's byte content as a downloadable attachment.
  10. The Content-Disposition header sets the download filename using the current date and time.
  11. The Content-Type header is set to "application/vnd.openxmlformats-officedocument.wordprocessingml.document" to indicate a Word file format.

常見問題解答

在 Azure 上設定 IronWord 的第一步是什麼?

要在 Azure 上設定 IronWord,第一步是建立 Azure 帳戶(如果您還沒有帳戶)。然後,您需要設定一個新的 Azure 應用程式服務,並將使用 IronWord 部署您的 .NET 應用程式。

如何在 Azure 上使用 IronWord 部署 .NET 應用程式?

要在 Azure 上使用 IronWord 部署 .NET 應用程序,您應該將應用程式及其相依性(包括 IronWord 程式庫)打包,然後將其上傳到 Azure 應用程式服務。您可以使用 Visual Studio Publish 或 Azure DevOps Pipelines 等工具來完成此過程。

執行 IronWord 是否需要任何特定的 Azure 服務?

IronWord 可以在標準 Azure 應用程式服務上運作。但是,為了獲得最佳效能,建議使用能夠根據應用程式需求提供充足資源的方案。

IronWord 可以與 Azure Functions 一起使用嗎?

是的,IronWord 可以與 Azure Functions 集成,以在無伺服器架構中處理 Word 文件。請確保 Azure Functions 環境具備 IronWord 所需的依賴項。

IronWord 如何增強 Azure 上的 Word 文件處理能力?

IronWord 透過提供強大的 .NET 程式庫來增強 Azure 上的 Word 文件處理能力,這些程式庫可以輕鬆與 Azure 服務集成,從而實現 Word 文件的高效建立、操作和轉換。

有沒有辦法在 Azure 上自動執行 IronWord 任務?

是的,您可以使用 Azure 邏輯應用程式或 Azure 函數在 Azure 上自動執行 IronWord 任務,根據特定事件或計畫觸發 Word 文件處理。

在 Azure 上使用 IronWord 有哪些好處?

在 Azure 上使用 IronWord 可以實現可擴展且可靠的 Word 文檔處理,利用 Azure 的雲端基礎架構來處理大量文檔,同時保持高效能。

我可以將 IronWord 與 Azure Blob 儲存體整合嗎?

是的,您可以將 IronWord 與 Azure Blob 儲存體集成,以儲存和擷取 Word 文檔,從而在您的 Azure 環境中實現無縫的文件處理和儲存管理。

如何確保 IronWord 在 Azure 上有效運作?

為確保 IronWord 在 Azure 上有效地運行,請選擇與您的工作負載相符的正確服務計劃,優化應用程式程式碼,並實施適當的錯誤處理和日誌記錄以進行故障排除。

在 Azure 上使用 IronWord 有什麼先決條件嗎?

在 Azure 上使用 IronWord 的先決條件包括:已設定 .NET 環境、具有必要權限的 Azure 帳戶以及專案中已包含 IronWord 程式庫。

A PHP Error was encountered

Severity: Warning

Message: Illegal string offset 'name'

Filename: sections/author_component.php

Line Number: 18

Backtrace:

File: /var/www/ironpdf.com/application/views/main/sections/author_component.php
Line: 18
Function: _error_handler

File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 63
Function: view

File: /var/www/ironpdf.com/application/views/products/sections/three_column_docs_page_structure.php
Line: 64
Function: main_view

File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 88
Function: view

File: /var/www/ironpdf.com/application/views/products/get-started/index.php
Line: 2
Function: view

File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 88
Function: view

File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 552
Function: view

File: /var/www/ironpdf.com/application/controllers/Products/Getstarted.php
Line: 25
Function: render_products_view

File: /var/www/ironpdf.com/index.php
Line: 292
Function: require_once

A PHP Error was encountered

Severity: Warning

Message: Illegal string offset 'title'

Filename: sections/author_component.php

Line Number: 38

Backtrace:

File: /var/www/ironpdf.com/application/views/main/sections/author_component.php
Line: 38
Function: _error_handler

File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 63
Function: view

File: /var/www/ironpdf.com/application/views/products/sections/three_column_docs_page_structure.php
Line: 64
Function: main_view

File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 88
Function: view

File: /var/www/ironpdf.com/application/views/products/get-started/index.php
Line: 2
Function: view

File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 88
Function: view

File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 552
Function: view

File: /var/www/ironpdf.com/application/controllers/Products/Getstarted.php
Line: 25
Function: render_products_view

File: /var/www/ironpdf.com/index.php
Line: 292
Function: require_once

A PHP Error was encountered

Severity: Warning

Message: Illegal string offset 'comment'

Filename: sections/author_component.php

Line Number: 48

Backtrace:

File: /var/www/ironpdf.com/application/views/main/sections/author_component.php
Line: 48
Function: _error_handler

File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 63
Function: view

File: /var/www/ironpdf.com/application/views/products/sections/three_column_docs_page_structure.php
Line: 64
Function: main_view

File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 88
Function: view

File: /var/www/ironpdf.com/application/views/products/get-started/index.php
Line: 2
Function: view

File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 88
Function: view

File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 552
Function: view

File: /var/www/ironpdf.com/application/controllers/Products/Getstarted.php
Line: 25
Function: render_products_view

File: /var/www/ironpdf.com/index.php
Line: 292
Function: require_once

準備好開始了嗎?
Nuget 下載 25,807 | 版本: 2025.11 剛剛發布