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は、Wordドキュメントをプログラムで作成、編集、読み取るための強力な.NETライブラリです。 Azure App Services、Azure Functions、Azure Container Instancesなど、さまざまなAzureサービスでシームレスに動作します。

IronWordのインストール

公式NuGetリポジトリからIronWord NuGetパッケージをインストールして始めましょう。

Install-Package IronWord

Azureでのホスティングの考慮事項

適切なAzureサービスタイアの選択

IronWordは、安定した計算資源を提供するAzureサービスプランで最高のパフォーマンスを発揮します。 ほとんどの小規模から中規模の利用ケースでは、Basic(B1)App Service Planで十分です。 アプリケーションが大量のWordドキュメントを処理する場合や、複雑なフォーマットのタスクを実行する場合、 パフォーマンスのボトルネックを避けるために、Standard(S1)またはそれ以上のティアへのアップグレードを検討してください。 ### 対応する.NETランタイムと互換性 IronWordは、Azureホストソリューションで一般的に使用されている次のフレームワークでそのまま動作します。

  • .NET 6+(LTS推奨)

AzureでのDockerでの展開

IronWordを使用したコンテナ化された展開

これにより、App Services、Azure Functions、Dockerコンテナなど、さまざまなAzureサービス全体でIronWordを展開する柔軟性があります。

AzureでのDockerでの展開

IronWordを使用したコンテナ化された展開

ランタイム環境を最大限に制御したい場合は、Dockerコンテナ内でIronWordをAzure Container Instances(ACI)またはAzure Kubernetes Service(AKS)で展開することを検討してください。

これにより、以下のことが可能になります:

  • テンプレートや静的リソースを事前にロードする

  • ドキュメント処理の設定を構成する - OSレベルでのパフォーマンスを微調整する

始めるには、例えばmcr.microsoft.com/dotnet/aspnet:6.0または7.0のようなベースイメージを使用し、NuGetまたは手動のDLL追加を通じてIronWordを追加します。

Azure Functionsでのサーバーレス

Azure FunctionsでのIronWordの使用

IronWordは、.NET 6以降で実行されるAzure Functions v4に完全に対応しています。

これは軽量でイベント駆動のドキュメント生成を可能にし、以下のようなシナリオに最適です:

  • HTTPを介したオンデマンドのレポート作成

  • フォーム送信からのWordドキュメント生成 - 構造的なデータを.docx形式に変換する

Azure Functionの例:リクエストに応じたWordドキュメントの生成

以下は、HTTPリクエストに応じてWordドキュメントを生成して返すAzure Functionの実例です: コードの説明:

  1. "GenerateWordDoc"という名前のAzure Functionを定義します。

  2. 関数はHTTP GETまたはPOSTリクエストによってトリガーされ、処理が始まるとメッセージをログに記録します。
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
  1. IronWordのライセンスキーを指定するために、IronWord.License.LicenseKey("YOUR-LICENSE-KEY"を実際のキーに置き換えます)を設定します。

  2. IronWordのAPIを使用して新しいWordDocumentが作成されます。
  3. ドキュメントには2つの段落が追加されます — 1つは静的テキスト、もう1つは現在のUTCタイムスタンプを表示します。
  4. ドキュメントはdoc.SaveAs(tempPath)を使用してサーバー上の一時的な.docxファイルに保存されます。
  5. 保存されたファイルは、ダウンロードの準備のためにFile.ReadAllBytesを使用してバイト配列に読み込まれます。
  6. 一時ファイルは、システムをクリーンに保つために読み取り直後に削除されます。
  7. ドキュメントのバイトコンテンツをダウンロード可能な添付ファイルとして含むHttpResponseMessageが構築されます。
  8. Content-Dispositionヘッダーは、現在の日付および時間を使用したダウンロードファイル名を設定します。
  9. Content-Typeヘッダーは、Wordファイル形式を指示するために"application/vnd.openxmlformats-officedocument.wordprocessingml.document"に設定されています。
  10. An HttpResponseMessage is built, containing the document's byte content as a downloadable attachment.
  11. The Content-Disposition header sets the download filename using the current date and time.
  12. The Content-Type header is set to "application/vnd.openxmlformats-officedocument.wordprocessingml.document" to indicate a Word file format.

よくある質問

AzureでIronWordを設定するための最初のステップは何ですか?

AzureでIronWordを設定するための最初のステップは、Azureアカウントを作成することです。既にアカウントを持っていない場合は、次に、.NETアプリケーションをIronWordを使用してデプロイする新しいAzure App Serviceを設定する必要があります。

AzureでIronWordを使用して.NETアプリケーションをデプロイするにはどうすればよいですか?

AzureでIronWordを使用して.NETアプリケーションをデプロイするには、アプリケーションとその依存関係をパッケージ化し、IronWordライブラリを含めてAzure App Serviceにアップロードします。このプロセスには、Visual Studio PublishやAzure DevOpsパイプラインのようなツールを使用できます。

IronWordを実行するために特定のAzureサービスが必要ですか?

IronWordは標準のAzure App Servicesで実行できます。ただし、最適なパフォーマンスを得るには、アプリケーションの要求に応じた十分なリソースを提供するプランを使用することをお勧めします。

IronWordはAzure Functionsと一緒に使用できますか?

はい、IronWordはAzure Functionsと統合して、サーバーレスアーキテクチャの一部としてWordドキュメントを処理することができます。Azure Function環境にIronWordの必要な依存関係があることを確認してください。

IronWordはどのようにしてAzure上でのWordドキュメント処理を向上させますか?

IronWordはAzure上でのWordドキュメント処理を強化し、強力な.NETライブラリを提供し、Azureサービスと簡単に統合でき、Wordドキュメントの効率的な作成、操作、および変換を可能にします。

Azure上でIronWordタスクを自動化する方法はありますか?

はい、特定のイベントやスケジュールに基づいてWordドキュメント処理をトリガーするAzure Logic AppsやAzure Functionsを使用して、Azure上でIronWordタスクを自動化できます。

IronWordをAzure上で使用する利点は何ですか?

Azure上でIronWordを使用することで、スケーラブルで信頼性の高いWordドキュメント処理が可能になり、Azureのクラウドインフラストラクチャを活用して大量のドキュメントを扱いつつ、高いパフォーマンスを維持します。

IronWordをAzure Blob Storageに統合することはできますか?

はい、IronWordをAzure Blob Storageと統合してWordドキュメントを保存および取得し、Azure環境内のドキュメント処理とストレージ管理をシームレスに行うことができます。

Azure上でIronWordを効率的に実行する方法を教えてください。

Azure上でIronWordを効率的に実行するためには、作業負荷に合ったサービスプランを選択し、アプリケーションのコードを最適化し、トラブルシューティングのための適切なエラーハンドリングとログ記録を実装します。

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 ただ今リリースされました