
BlazorサーバーでRazorをPDFに変換する方法
Kaizen.io HTML-to-PDFからIronPDFへの移行は、HTTPを介して公開された自己ホスティングのDockerコンテナをインプロセス for .NETライブラリに置き換えます。 Kaizen.io HTML-to-PDFはDockerイメージPOST /html-to-pdfを公開しています。公式 for .NET SDKやNuGetパッケージはないため、すべてのC#呼び出しは実行中のコンテナに対してHttpClientを使用して手動で行う必要があります。 このガイドでは、そのパターンをIronPDFのChromePdfRendererに置き換える方法を解説します。
Kaizen.ioからIronPDFへ移行する理由
コンテナAPIの課題
Kaizen.io HTML-to-PDFは意図的に小さなv1.x APIを持つDockerコンテナであり、C#の統合ストーリーはHttpClientの上に自分で構築するものです。 その形状は、本番での限界が現実にあります:
-
操作するコンテナ: アプリから到達可能な場所に
kaizenio.azurecr.io/html-to-pdf:latestを実行、監視、および更新します。ローカルDocker、サイドカー、または別ホストで可能です。 -
.NET SDKなし: すべてのC#呼び出しは
HttpClientPOST + JSONとして手動で行います。 IntelliSenseもリクエスト形状のコンパイル時チェックもありません。 -
小さなv1.x APIサーフェス: ドキュメント化されたJSONボディは
htmlフィールドのみを受け付けます。 URL-to-PDF、カスタムスタイルシート、ヘッダー/フッター、ページサイズ、向き、および余白は、出荷機能ではなくロードマップ項目として記載されています。HTML文字列のレンダリングを超えるものはすべて、通常は@pageCSSと絶対位置のdivを通じて、HTML自体の中に表現する必要があります。 -
ページ番号サポートなし: APIには
{page}/{total}プレースホルダーがないため、"ページX of Y"フッターはサーバー側で生成できません。 -
PDFごとのHTTP往復: コンテナが
localhostで実行されている場合でも、すべてのPDFはJSONシリアライゼーションとソケットホップを必要とします。 -
無料プランでの透かし: コンテナで
KAIZEN_PDF_LICENSE環境変数が設定されていない場合、出力に透かしが入ります。
Kaizen.ioとIronPDFの比較
| フィーチャー | Kaizen.io HTML-to-PDF | IronPDF |
|---|---|---|
| 配布 | Dockerイメージkaizenio.azurecr.io/html-to-pdf | NuGetIronPdf |
| C# 統合 | 手書きのHttpClient POST(SDKなし) | 厳密に型指定されたChromePdfRenderer API |
| プロセスモデル | アウトオブプロセス コンテナ | 進行中 |
| エンドポイント サーフェス (v1.x) | POST /html-to-pdf with { "html": ... } | HTML、ファイル、URL用のメソッド |
| URL 入力 | ロードマップ | RenderUrlAsPdf(url) |
| ヘッダー / フッター | v1.x API には存在しません; 固定位置 CSS による偽装 | TextHeader/Footer and HtmlHeader/Footer |
| ページ数 | 未対応 | {total-pages}プレースホルダー |
| ページサイズ / オリエンテーション | HTMLに@page CSSを埋め込み | RenderingOptions.PaperSize 他 |
| ライセンス | 一度きりのライセンス; 透かし入りのフリー層 | 商用(年次または永続) |
モダン .NET を標準化するチームには、IronPDF はサイドカー コンテナと HTTP ホップをリクエスト パスから取り除き、強く型付けされた構成サーフェスを公開します。
マイグレーションの複雑さの評価
機能別の見積もり作業
| フィーチャー | 移行の複雑さ |
|---|---|
| 基本的なHTMLからPDFへ | 低レベル |
| HTMLファイルからPDFへ | 低レベル |
| URLからPDFへ | 低(Kaizen v1.x には URL エンドポイントがありません - 漏斗全体が置換されます) |
| ヘッダー/フッター | 中(偽装された CSS div は本物のヘッダーゾーンに置換されます) |
| ページ数 | 新機能(Kaizen v1.x では利用できません) |
| ページ設定 | 低 (@page CSSがRenderingOptionsに移動) |
パラダイムシフト
アウトオブプロセス HTTP 呼び出しから Docker コンテナへの基本的なシフトは、インプロセスレンダリングへ:
Kaizen.io: HttpClient.PostAsync("http://.../html-to-pdf", { html }) → byte[]
IronPDF: ChromePdfRenderer → RenderHtmlAsPdf(html) → PdfDocument
始める前に
前提条件
- .NET 環境: .NET Framework 4.6.2+ または .NET Core 3.1+ / .NET 5+
- NuGetアクセス: NuGetパッケージをインストールする機能
- IronPDFライセンス: IronPDFからライセンスキーを取得します。
パッケージの変更
Kaizen NuGet パッケージを削除する必要はありません - Kaizen は Docker イメージとしてのみ提供されます。 コンテナを停止し、IronPDF パッケージを追加してください:
# Stop and remove the running Kaizen container (if any)
docker stop kaizen-pdf
docker rm kaizen-pdf
# Install IronPDF
dotnet add package IronPdf
ライセンス構成
// Add at application startup (Program.cs or Startup.cs)
IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY";' Add at application startup (Program.vb or Startup.vb)
IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY"' Add at application startup (Program.vb or Startup.vb)
IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY"Kaizen.ioの使用法を特定する
KaizenにはSDKがないため、その呼び出しはHttpClient POSTのように見えます。 エンドポイント、イメージ名、ライセンス env var を名前空間とではなく検索します:
grep -r "html-to-pdf\|KAIZEN_PDF_LICENSE\|kaizenio.azurecr.io\|localhost:8080" \
--include="*.cs" --include="*.json" --include="*.yml" .
完全な API リファレンス
コンセプト マッピング
マップする Kaizen .NET クラスはありません - JSON リクエスト形状とそれに基づいて構築した規約のみがあります。
| Kaizen.io コンセプト | IronPDF 同等物 |
|---|---|
HttpClient + POST /html-to-pdf | ChromePdfRenderer |
JSON { "html": "..." }ボディ | RenderHtmlAsPdf(string html) |
| (No URL field in v1.x) | RenderUrlAsPdf(string url) |
| (No file field in v1.x) | RenderHtmlFileAsPdf(string path) |
インライン @page CSS for size | RenderingOptions.PaperSize |
インライン @page CSS for orientation | RenderingOptions.PaperOrientation |
インライン @page { margin: ... } | RenderingOptions.MarginTop/Bottom/Left/Right |
固定位置の<div class='header'> ハック | RenderingOptions.TextHeader / HtmlHeader |
固定位置の<div class='footer'> ハック | RenderingOptions.TextFooter / HtmlFooter |
HttpClient.PostAsync | RenderHtmlAsPdfAsync |
コンテナ環境変数KAIZEN_PDF_LICENSE | IronPdf.License.LicenseKey |
HTTP byte[] レスポンス | pdf.BinaryData / pdf.SaveAs(path) |
プレースホルダーのマッピング
Kaizen v1.x にはサーバー側のプレースホルダーは存在しません。 以前に文字列を手で HTML に置換して POST したのであれば、IronPDF のレンダリング時プレースホルダーに切り替えてください:
| 以前のやり方 | IronPDF プレースホルダー |
|---|---|
html.Replace("{page}", currentPage.ToString()) | {page} |
html.Replace("{total}", total.ToString()) | {total-pages} |
html.Replace("{date}", DateTime.Now.ToShortDateString()) | {date} |
html.Replace("{title}", docTitle) | {html-title} |
コード移行の例
例1: 基本的なHTMLからPDFへ
以前(Kaizen.io - コンテナへ JSON を POST):
// Container must be running:
// docker run -d -p 8080:8080 -e KAIZEN_PDF_LICENSE=... \
// kaizenio.azurecr.io/html-to-pdf:latest
using System.IO;
using System.Net.Http;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
class Program
{
static async Task Main()
{
using var http = new HttpClient();
var payload = JsonSerializer.Serialize(new { html = "<html><body><h1>Hello World</h1></body></html>" });
var content = new StringContent(payload, Encoding.UTF8, "application/json");
var response = await http.PostAsync("http://localhost:8080/html-to-pdf", content);
response.EnsureSuccessStatusCode();
var pdfBytes = await response.Content.ReadAsByteArrayAsync();
File.WriteAllBytes("output.pdf", pdfBytes);
}
}// Container must be running:
// docker run -d -p 8080:8080 -e KAIZEN_PDF_LICENSE=... \
// kaizenio.azurecr.io/html-to-pdf:latest
using System.IO;
using System.Net.Http;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
class Program
{
static async Task Main()
{
using var http = new HttpClient();
var payload = JsonSerializer.Serialize(new { html = "<html><body><h1>Hello World</h1></body></html>" });
var content = new StringContent(payload, Encoding.UTF8, "application/json");
var response = await http.PostAsync("http://localhost:8080/html-to-pdf", content);
response.EnsureSuccessStatusCode();
var pdfBytes = await response.Content.ReadAsByteArrayAsync();
File.WriteAllBytes("output.pdf", pdfBytes);
}
}Imports System.IO
Imports System.Net.Http
Imports System.Text
Imports System.Text.Json
Imports System.Threading.Tasks
Module Program
Async Function Main() As Task
Using http As New HttpClient()
Dim payload = JsonSerializer.Serialize(New With {.html = "<html><body><h1>Hello World</h1></body></html>"})
Dim content As New StringContent(payload, Encoding.UTF8, "application/json")
Dim response = Await http.PostAsync("http://localhost:8080/html-to-pdf", content)
response.EnsureSuccessStatusCode()
Dim pdfBytes = Await response.Content.ReadAsByteArrayAsync()
File.WriteAllBytes("output.pdf", pdfBytes)
End Using
End Function
End ModuleImports System.IO
Imports System.Net.Http
Imports System.Text
Imports System.Text.Json
Imports System.Threading.Tasks
Module Program
Async Function Main() As Task
Using http As New HttpClient()
Dim payload = JsonSerializer.Serialize(New With {.html = "<html><body><h1>Hello World</h1></body></html>"})
Dim content As New StringContent(payload, Encoding.UTF8, "application/json")
Dim response = Await http.PostAsync("http://localhost:8080/html-to-pdf", content)
response.EnsureSuccessStatusCode()
Dim pdfBytes = Await response.Content.ReadAsByteArrayAsync()
File.WriteAllBytes("output.pdf", pdfBytes)
End Using
End Function
End Module翻訳後(IronPDF):。
// NuGet: Install-Package IronPdf
using IronPdf;
using System.IO;
class Program
{
static void Main()
{
var renderer = new ChromePdfRenderer();
var html = "<html><body><h1>Hello World</h1></body></html>";
var pdf = renderer.RenderHtmlAsPdf(html);
pdf.SaveAs("output.pdf");
}
}// NuGet: Install-Package IronPdf
using IronPdf;
using System.IO;
class Program
{
static void Main()
{
var renderer = new ChromePdfRenderer();
var html = "<html><body><h1>Hello World</h1></body></html>";
var pdf = renderer.RenderHtmlAsPdf(html);
pdf.SaveAs("output.pdf");
}
}Imports IronPdf
Imports System.IO
Class Program
Shared Sub Main()
Dim renderer = New ChromePdfRenderer()
Dim html = "<html><body><h1>Hello World</h1></body></html>"
Dim pdf = renderer.RenderHtmlAsPdf(html)
pdf.SaveAs("output.pdf")
End Sub
End ClassImports IronPdf
Imports System.IO
Class Program
Shared Sub Main()
Dim renderer = New ChromePdfRenderer()
Dim html = "<html><body><h1>Hello World</h1></body></html>"
Dim pdf = renderer.RenderHtmlAsPdf(html)
pdf.SaveAs("output.pdf")
End Sub
End ClassKaizen.io のアプローチは、JSON をシリアライズし、それをコンテナの REST エンドポイントに送信し、ステータスコードを確認し、応答をバイトとして読み取り、それらのバイトをディスクに書き込みます。 IronPDFのSaveAs()メソッドを持っているため、往復と手動でのバイト処理は不要になります。 その他のレンダリングオプションについては、HTML to PDF documentationを参照してください。
例2: ページ設定でHTMLファイルをPDFに
Kaizen v1.xにはファイルエンドポイントがなく、ページレイアウトフィールドがありません。ファイルを自分で読み取り、ページサイズ/向きを@page CSSに埋め込みます。
翻訳前 (Kaizen.io):
using System.IO;
using System.Net.Http;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
class Program
{
static async Task Main()
{
var body = File.ReadAllText("input.html");
var html = "<style>@page { size: A4 portrait; }</style>" + body;
using var http = new HttpClient();
var payload = JsonSerializer.Serialize(new { html });
var response = await http.PostAsync(
"http://localhost:8080/html-to-pdf",
new StringContent(payload, Encoding.UTF8, "application/json"));
response.EnsureSuccessStatusCode();
File.WriteAllBytes("document.pdf", await response.Content.ReadAsByteArrayAsync());
}
}using System.IO;
using System.Net.Http;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
class Program
{
static async Task Main()
{
var body = File.ReadAllText("input.html");
var html = "<style>@page { size: A4 portrait; }</style>" + body;
using var http = new HttpClient();
var payload = JsonSerializer.Serialize(new { html });
var response = await http.PostAsync(
"http://localhost:8080/html-to-pdf",
new StringContent(payload, Encoding.UTF8, "application/json"));
response.EnsureSuccessStatusCode();
File.WriteAllBytes("document.pdf", await response.Content.ReadAsByteArrayAsync());
}
}Imports System.IO
Imports System.Net.Http
Imports System.Text
Imports System.Text.Json
Imports System.Threading.Tasks
Module Program
Async Function Main() As Task
Dim body = File.ReadAllText("input.html")
Dim html = "<style>@page { size: A4 portrait; }</style>" & body
Using http As New HttpClient()
Dim payload = JsonSerializer.Serialize(New With {Key .html = html})
Dim response = Await http.PostAsync(
"http://localhost:8080/html-to-pdf",
New StringContent(payload, Encoding.UTF8, "application/json"))
response.EnsureSuccessStatusCode()
File.WriteAllBytes("document.pdf", Await response.Content.ReadAsByteArrayAsync())
End Using
End Function
End ModuleImports System.IO
Imports System.Net.Http
Imports System.Text
Imports System.Text.Json
Imports System.Threading.Tasks
Module Program
Async Function Main() As Task
Dim body = File.ReadAllText("input.html")
Dim html = "<style>@page { size: A4 portrait; }</style>" & body
Using http As New HttpClient()
Dim payload = JsonSerializer.Serialize(New With {Key .html = html})
Dim response = Await http.PostAsync(
"http://localhost:8080/html-to-pdf",
New StringContent(payload, Encoding.UTF8, "application/json"))
response.EnsureSuccessStatusCode()
File.WriteAllBytes("document.pdf", Await response.Content.ReadAsByteArrayAsync())
End Using
End Function
End Module翻訳後(IronPDF):。
// NuGet: Install-Package IronPdf
using IronPdf;
class Program
{
static void Main()
{
var renderer = new ChromePdfRenderer();
renderer.RenderingOptions.PaperSize = PdfPaperSize.A4;
renderer.RenderingOptions.PaperOrientation = PdfPaperOrientation.Portrait;
var pdf = renderer.RenderHtmlFileAsPdf("input.html");
pdf.SaveAs("document.pdf");
}
}// NuGet: Install-Package IronPdf
using IronPdf;
class Program
{
static void Main()
{
var renderer = new ChromePdfRenderer();
renderer.RenderingOptions.PaperSize = PdfPaperSize.A4;
renderer.RenderingOptions.PaperOrientation = PdfPaperOrientation.Portrait;
var pdf = renderer.RenderHtmlFileAsPdf("input.html");
pdf.SaveAs("document.pdf");
}
}Imports IronPdf
Class Program
Shared Sub Main()
Dim renderer = New ChromePdfRenderer()
renderer.RenderingOptions.PaperSize = PdfPaperSize.A4
renderer.RenderingOptions.PaperOrientation = PdfPaperOrientation.Portrait
Dim pdf = renderer.RenderHtmlFileAsPdf("input.html")
pdf.SaveAs("document.pdf")
End Sub
End ClassImports IronPdf
Class Program
Shared Sub Main()
Dim renderer = New ChromePdfRenderer()
renderer.RenderingOptions.PaperSize = PdfPaperSize.A4
renderer.RenderingOptions.PaperOrientation = PdfPaperOrientation.Portrait
Dim pdf = renderer.RenderHtmlFileAsPdf("input.html")
pdf.SaveAs("document.pdf")
End Sub
End Class@page CSSからRenderingOptionsプロパティに移動します。
例3: ヘッダーとフッター付きのURLからPDFへ
Kaizen v1.xにはConvertUrlがなく、ヘッダー/フッターフィールドがなく、ページ番号プレースホルダーもありません。 回避策はページを自分で取得して@page CSSと固定位置のdivでラップし、ヘッダー/フッターを模倣することですが、ページ番号をレンダリングする方法はありません。
翻訳前 (Kaizen.io):
using System.IO;
using System.Net.Http;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
class Program
{
static async Task Main()
{
using var http = new HttpClient();
var page = await http.GetStringAsync("https://example.com");
var html = $@"<!doctype html><html><head><style>
@page {{margin: 20mm;}}
.h {{position: fixed; top: -15mm; left: 0; right: 0; text-align: center;}}
.f {{position: fixed; bottom: -15mm; left: 0; right: 0; text-align: center;}}
</style></head><body>
<div class='h'>Company Header</div>
<div class='f'>Footer (page numbers unsupported in Kaizen v1.x)</div>
{page}
</body></html>";
var payload = JsonSerializer.Serialize(new { html });
var response = await http.PostAsync(
"http://localhost:8080/html-to-pdf",
new StringContent(payload, Encoding.UTF8, "application/json"));
response.EnsureSuccessStatusCode();
File.WriteAllBytes("webpage.pdf", await response.Content.ReadAsByteArrayAsync());
}
}using System.IO;
using System.Net.Http;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
class Program
{
static async Task Main()
{
using var http = new HttpClient();
var page = await http.GetStringAsync("https://example.com");
var html = $@"<!doctype html><html><head><style>
@page {{margin: 20mm;}}
.h {{position: fixed; top: -15mm; left: 0; right: 0; text-align: center;}}
.f {{position: fixed; bottom: -15mm; left: 0; right: 0; text-align: center;}}
</style></head><body>
<div class='h'>Company Header</div>
<div class='f'>Footer (page numbers unsupported in Kaizen v1.x)</div>
{page}
</body></html>";
var payload = JsonSerializer.Serialize(new { html });
var response = await http.PostAsync(
"http://localhost:8080/html-to-pdf",
new StringContent(payload, Encoding.UTF8, "application/json"));
response.EnsureSuccessStatusCode();
File.WriteAllBytes("webpage.pdf", await response.Content.ReadAsByteArrayAsync());
}
}Imports System.IO
Imports System.Net.Http
Imports System.Text
Imports System.Text.Json
Imports System.Threading.Tasks
Module Program
Async Function Main() As Task
Using http = New HttpClient()
Dim page = Await http.GetStringAsync("https://example.com")
Dim html = $"<!doctype html><html><head><style>
@page {{margin: 20mm;}}
.h {{position: fixed; top: -15mm; left: 0; right: 0; text-align: center;}}
.f {{position: fixed; bottom: -15mm; left: 0; right: 0; text-align: center;}}
</style></head><body>
<div class='h'>Company Header</div>
<div class='f'>Footer (page numbers unsupported in Kaizen v1.x)</div>
{page}
</body></html>"
Dim payload = JsonSerializer.Serialize(New With {html})
Dim response = Await http.PostAsync("http://localhost:8080/html-to-pdf", New StringContent(payload, Encoding.UTF8, "application/json"))
response.EnsureSuccessStatusCode()
File.WriteAllBytes("webpage.pdf", Await response.Content.ReadAsByteArrayAsync())
End Using
End Function
End ModuleImports System.IO
Imports System.Net.Http
Imports System.Text
Imports System.Text.Json
Imports System.Threading.Tasks
Module Program
Async Function Main() As Task
Using http = New HttpClient()
Dim page = Await http.GetStringAsync("https://example.com")
Dim html = $"<!doctype html><html><head><style>
@page {{margin: 20mm;}}
.h {{position: fixed; top: -15mm; left: 0; right: 0; text-align: center;}}
.f {{position: fixed; bottom: -15mm; left: 0; right: 0; text-align: center;}}
</style></head><body>
<div class='h'>Company Header</div>
<div class='f'>Footer (page numbers unsupported in Kaizen v1.x)</div>
{page}
</body></html>"
Dim payload = JsonSerializer.Serialize(New With {html})
Dim response = Await http.PostAsync("http://localhost:8080/html-to-pdf", New StringContent(payload, Encoding.UTF8, "application/json"))
response.EnsureSuccessStatusCode()
File.WriteAllBytes("webpage.pdf", Await response.Content.ReadAsByteArrayAsync())
End Using
End Function
End Module翻訳後(IronPDF):。
// NuGet: Install-Package IronPdf
using IronPdf;
class Program
{
static void Main()
{
var renderer = new ChromePdfRenderer();
renderer.RenderingOptions.TextHeader.CenterText = "Company Header";
renderer.RenderingOptions.TextFooter.CenterText = "Page {page} of {total-pages}";
renderer.RenderingOptions.MarginTop = 20;
renderer.RenderingOptions.MarginBottom = 20;
var pdf = renderer.RenderUrlAsPdf("https://example.com");
pdf.SaveAs("webpage.pdf");
}
}// NuGet: Install-Package IronPdf
using IronPdf;
class Program
{
static void Main()
{
var renderer = new ChromePdfRenderer();
renderer.RenderingOptions.TextHeader.CenterText = "Company Header";
renderer.RenderingOptions.TextFooter.CenterText = "Page {page} of {total-pages}";
renderer.RenderingOptions.MarginTop = 20;
renderer.RenderingOptions.MarginBottom = 20;
var pdf = renderer.RenderUrlAsPdf("https://example.com");
pdf.SaveAs("webpage.pdf");
}
}Imports IronPdf
Class Program
Shared Sub Main()
Dim renderer = New ChromePdfRenderer()
renderer.RenderingOptions.TextHeader.CenterText = "Company Header"
renderer.RenderingOptions.TextFooter.CenterText = "Page {page} of {total-pages}"
renderer.RenderingOptions.MarginTop = 20
renderer.RenderingOptions.MarginBottom = 20
Dim pdf = renderer.RenderUrlAsPdf("https://example.com")
pdf.SaveAs("webpage.pdf")
End Sub
End ClassImports IronPdf
Class Program
Shared Sub Main()
Dim renderer = New ChromePdfRenderer()
renderer.RenderingOptions.TextHeader.CenterText = "Company Header"
renderer.RenderingOptions.TextFooter.CenterText = "Page {page} of {total-pages}"
renderer.RenderingOptions.MarginTop = 20
renderer.RenderingOptions.MarginBottom = 20
Dim pdf = renderer.RenderUrlAsPdf("https://example.com")
pdf.SaveAs("webpage.pdf")
End Sub
End ClassTextHeader / TextFooterゾーンに置き換えられます。 ページ番号は{total-pages}プレースホルダーで生成されますが、Kaizen v1.xはこれを提供しません。URL-to-PDF変換とヘッダーとフッターについて詳しく学びます。
重要な移行に関する注意事項
ライセンスはコード内にあり、コンテナ内にはありません
KaizenのライセンスはDockerコンテナ上のKAIZEN_PDF_LICENSE環境変数で構成されます。IronPDFのライセンスはアプリケーションのスタートアップ時に一回設定された静的プロパティです:
// DELETE the Kaizen container env var:
// docker run ... -e KAIZEN_PDF_LICENSE=... kaizenio.azurecr.io/html-to-pdf
// IronPDF: set once at startup
IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY";
var renderer = new ChromePdfRenderer();// DELETE the Kaizen container env var:
// docker run ... -e KAIZEN_PDF_LICENSE=... kaizenio.azurecr.io/html-to-pdf
// IronPDF: set once at startup
IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY";
var renderer = new ChromePdfRenderer();' DELETE the Kaizen container env var:
' docker run ... -e KAIZEN_PDF_LICENSE=... kaizenio.azurecr.io/html-to-pdf
' IronPDF: set once at startup
IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY"
Dim renderer As New ChromePdfRenderer()' DELETE the Kaizen container env var:
' docker run ... -e KAIZEN_PDF_LICENSE=... kaizenio.azurecr.io/html-to-pdf
' IronPDF: set once at startup
IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY"
Dim renderer As New ChromePdfRenderer()プレースホルダー構文
以前に文字列を手で HTML に置換して POST したのであれば、IronPDF のレンダリング時プレースホルダーに切り替えてください:
{page}(変更されていない){total}→{total-pages}{title}→{html-title}{date}→{date}(変更されていない)
返品タイプの変更
KaizenはHTTPを介して生のバイトを返します。IronPDFはPdfDocumentを返します。
// Kaizen.io returns byte[] via HTTP
byte[] pdfBytes = await response.Content.ReadAsByteArrayAsync();
File.WriteAllBytes("output.pdf", pdfBytes);
//IronPDFreturns PdfDocument
var pdf = renderer.RenderHtmlAsPdf(html);
pdf.SaveAs("output.pdf"); // Direct save
byte[] bytes = pdf.BinaryData; // Or get bytes if needed// Kaizen.io returns byte[] via HTTP
byte[] pdfBytes = await response.Content.ReadAsByteArrayAsync();
File.WriteAllBytes("output.pdf", pdfBytes);
//IronPDFreturns PdfDocument
var pdf = renderer.RenderHtmlAsPdf(html);
pdf.SaveAs("output.pdf"); // Direct save
byte[] bytes = pdf.BinaryData; // Or get bytes if needed' Kaizen.io returns byte() via HTTP
Dim pdfBytes As Byte() = Await response.Content.ReadAsByteArrayAsync()
File.WriteAllBytes("output.pdf", pdfBytes)
' IronPDF returns PdfDocument
Dim pdf = renderer.RenderHtmlAsPdf(html)
pdf.SaveAs("output.pdf") ' Direct save
Dim bytes As Byte() = pdf.BinaryData ' Or get bytes if needed' Kaizen.io returns byte() via HTTP
Dim pdfBytes As Byte() = Await response.Content.ReadAsByteArrayAsync()
File.WriteAllBytes("output.pdf", pdfBytes)
' IronPDF returns PdfDocument
Dim pdf = renderer.RenderHtmlAsPdf(html)
pdf.SaveAs("output.pdf") ' Direct save
Dim bytes As Byte() = pdf.BinaryData ' Or get bytes if neededHTTP 配管の削除
レンダラーがインプロセスになると、サポートするコードが消えます:
// DELETE all of:
// - HttpClient lifetime management
// - JSON serialization of { html }
// - response.EnsureSuccessStatusCode() / status-code branches
// - "container unreachable" retry/backoff
// - ReadAsByteArrayAsync()
// Replaced with a single in-process call:
var pdf = renderer.RenderHtmlAsPdf(html);// DELETE all of:
// - HttpClient lifetime management
// - JSON serialization of { html }
// - response.EnsureSuccessStatusCode() / status-code branches
// - "container unreachable" retry/backoff
// - ReadAsByteArrayAsync()
// Replaced with a single in-process call:
var pdf = renderer.RenderHtmlAsPdf(html);netnetトラブルシューティング
問題 1: HtmlToPdfConverter クラスがありません
問題: 置き換えるためのHtmlToPdfConverterクラスがありません。Kaizenには.NET SDKがまったくありません。
解決策: 移行はコンテナに対するHttpClient POSTからChromePdfRendererへの移行です。
// Kaizen.io: hand-rolled HTTP
using var http = new HttpClient();
var response = await http.PostAsync("http://localhost:8080/html-to-pdf", content);
// IronPDF: in-process renderer
var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderHtmlAsPdf(html);// Kaizen.io: hand-rolled HTTP
using var http = new HttpClient();
var response = await http.PostAsync("http://localhost:8080/html-to-pdf", content);
// IronPDF: in-process renderer
var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderHtmlAsPdf(html);Imports System.Net.Http
Imports IronPdf
' Kaizen.io: hand-rolled HTTP
Using http As New HttpClient()
Dim response = Await http.PostAsync("http://localhost:8080/html-to-pdf", content)
End Using
' IronPDF: in-process renderer
Dim renderer As New ChromePdfRenderer()
Dim pdf = renderer.RenderHtmlAsPdf(html)Imports System.Net.Http
Imports IronPdf
' Kaizen.io: hand-rolled HTTP
Using http As New HttpClient()
Dim response = Await http.PostAsync("http://localhost:8080/html-to-pdf", content)
End Using
' IronPDF: in-process renderer
Dim renderer As New ChromePdfRenderer()
Dim pdf = renderer.RenderHtmlAsPdf(html)問題 2: オプション オブジェクトがどこに行ったのか?
問題: Kaizen v1.xには@page CSSであり、ヘッダー/フッターは固定位置のdivでした。
解決策: その設定をレンダラー上のRenderingOptionsに移動します。
// Before: <style>@page { size: A4 portrait; margin: 20mm; }</style>
renderer.RenderingOptions.PaperSize = PdfPaperSize.A4;
renderer.RenderingOptions.PaperOrientation = PdfPaperOrientation.Portrait;
renderer.RenderingOptions.MarginTop = 20;
renderer.RenderingOptions.MarginBottom = 20;// Before: <style>@page { size: A4 portrait; margin: 20mm; }</style>
renderer.RenderingOptions.PaperSize = PdfPaperSize.A4;
renderer.RenderingOptions.PaperOrientation = PdfPaperOrientation.Portrait;
renderer.RenderingOptions.MarginTop = 20;
renderer.RenderingOptions.MarginBottom = 20;' Before: <style>@page { size: A4 portrait; margin: 20mm; }</style>
renderer.RenderingOptions.PaperSize = PdfPaperSize.A4
renderer.RenderingOptions.PaperOrientation = PdfPaperOrientation.Portrait
renderer.RenderingOptions.MarginTop = 20
renderer.RenderingOptions.MarginBottom = 20' Before: <style>@page { size: A4 portrait; margin: 20mm; }</style>
renderer.RenderingOptions.PaperSize = PdfPaperSize.A4
renderer.RenderingOptions.PaperOrientation = PdfPaperOrientation.Portrait
renderer.RenderingOptions.MarginTop = 20
renderer.RenderingOptions.MarginBottom = 20問題 3: ページ番号がレンダリングされない
問題: Kaizen v1.xには{page}/ {total}プレースホルダーサポートがないため、移行前の"ページX of Y"フッターは欠落しているか静的テキストでした。
**解決策:**IronPDFのヘッダー/フッタープレースホルダーを使用してください:
renderer.RenderingOptions.TextFooter = new TextHeaderFooter
{
CenterText = "Page {page} of {total-pages}"
};renderer.RenderingOptions.TextFooter = new TextHeaderFooter
{
CenterText = "Page {page} of {total-pages}"
};renderer.RenderingOptions.TextFooter = New TextHeaderFooter With {
.CenterText = "Page {page} of {total-pages}"
}renderer.RenderingOptions.TextFooter = New TextHeaderFooter With {
.CenterText = "Page {page} of {total-pages}"
}投稿する前に自分のコードで{total-pages}をレンダー時に解決します。
問題 4: コンテナ接続エラー
問題: "コンテナが到達できない"/ ポート 8080 エラーの処理経路。
**解決策:**IronPDFはインプロセスで動作します - 接続するエンドポイントはありません。 接続エラー処理を削除してください。
課題5:最初のレンダリングが遅い
問題:最初の PDF 生成には 1 ~ 3 秒かかります。
**解決策:**IronPDFは、初めて使用するときに Chromium を初期化します。 アプリケーション起動時のウォームアップ
// In Program.cs or Startup.cs:
new ChromePdfRenderer().RenderHtmlAsPdf("<html></html>");// In Program.cs or Startup.cs:
new ChromePdfRenderer().RenderHtmlAsPdf("<html></html>");' In Program.vb or Startup.vb:
Call New ChromePdfRenderer().RenderHtmlAsPdf("<html></html>")' In Program.vb or Startup.vb:
Call New ChromePdfRenderer().RenderHtmlAsPdf("<html></html>")移行チェックリスト
移行前
- Kaizenの呼び出し箇所をすべて特定します(
localhost:8080を検索)。 - サイズ、向き、余白に使用されるインライン
@pageCSSを文書化します。 - 偽装されたヘッダー/フッター div(ネガティブ オフセットで固定位置)を文書化
- クライアント側プレースホルダー置換(
html.Replace("{page}", ...)など)を列挙します。 - コンテナのライフサイクルを記録:プル、実行、再起動、ライセンス env var
- IronPDFライセンスキーを取得する
コンテナの撤去
- 実行中のKaizenコンテナを停止および削除します(
docker stop kaizen-pdf && docker rm kaizen-pdf)。 - CI/CD から Kaizen プル/実行ステップを削除
- secrets/envから
KAIZEN_PDF_LICENSEを削除します。 IronPdfNuGetパッケージをインストールします(dotnet add package IronPdf)。
コードの変更
- 起動時にライセンスキー設定を追加する
HttpClientPOSTをChromePdfRendererに置き換えます。- 埋め込まれた
@pageCSSをRenderingOptionsプロパティに移動します。 - JSON POSTを
RenderHtmlAsPdf()/RenderHtmlFileAsPdf()/RenderUrlAsPdf()に置き換えます。 - 偽のヘッダー/フッターdivを
HtmlHeader/Footerに置き換えます。 - プレースホルダー構文を更新します(
{total}→{title}→{html-title})。 byte[]HTTPボディをpdf.BinaryDataに置き換えます。File.WriteAllBytes()の代わりに使用します。- コンテナ到達可能性エラー処理とリトライ/バックオフの削除
テスティング
- すべてのPDF生成パスをテストする
- ヘッダー/フッターレンダリングとページ番号(新機能)を確認
- マージン、ページサイズ、オリエンテーションを確認
- オフライン動作をテスト(コンテナ不要)
移行後
- Kaizen コンテナ インフラストラクチャの撤去
- 環境変数 / 秘密を更新
- 監視/アラートからコンテナの健康状態チェックを削除
- 新しい型付き例外エラーパターンを文書化
Curtis Chauは、カールトン大学でコンピュータサイエンスの学士号を取得し、Node.js、TypeScript、JavaScript、およびReactに精通したフロントエンド開発を専門としています。直感的で美しいユーザーインターフェースを作成することに情熱を持ち、Curtisは現代のフレームワークを用いた開発や、構造の良い視覚的に魅力的なマニュアルの作成を楽しんでいます。
関連する記事


