
How to convert HTML to PDF with C# in .NET | IronPDF
TX Text Controlは、.NETエコシステムにおける包括的なドキュメントエディターコンポーネントとしての地位を確立しており、UIコントロールを組み込んだ堅牢なDOCX編集機能を提供しています。 しかし、文書の完全な編集ではなく、PDFの生成が主な要件である開発チームにとって、TextControlのアーキテクチャは、ライセンスコスト、複雑さ、実行時の依存関係において、大きなオーバーヘッドをもたらします。
このガイドでは、TextControlからIronPDFへの完全な移行経路を、移行を検討しているプロ for .NET開発者のために、ステップバイステップの手順、コード比較、実用的な例で説明します。
なぜTextControlから移行するのか
通常、TextControlからの移行は、ツールを実際の要件に適合させることが中心になります。 TX Text Controlは基本的にドキュメントエディタで、PDF生成は二次的な機能として扱われます。 開発チームが移行を検討する主な理由は次のとおりです:
高額のライセンス: 1つのTX Text Control .NETサーバーデベロッパーライセンスは$4,198で永続的で、1年間のアップデート/サポートが付きます; 4人の開発者チームライセンスは$8,398で永続的で+1年です (textcontrol.comの価格による)。 年間のサブスクリプション更新はリスト価格の約40% (約$1,698/年/開発者) であり、有効期限の30日後に更新ウィンドウが閉じます。 本番展開には、別途サーバーランタイムライセンスも必要です。
二次的なPDFパス: コアアーキテクチャはワード処理エンジン (DOCX/RTF第一) であり、PDFは主ではなくエクスポート経路です。
バンドルエディタサーフェス: TX Text Controlは、DOCX編集UIコンポーネントを装備して出荷され、純粋にサーバーサイドでのPDF生成が要件である場合には不要な場面もあります。
ワードプロセッサアーキテクチャ: HTMLインポートはワード処理パイプラインを経由し、Chromiumベースのレンダラーを経由しないため、HTML5/CSS3の忠実度は通常ブラウザエンジンPDFライブラリよりも劣ります。
ASP.NETでのSTA依存性: ServerTextControlはSTA COMスタイルのコンポーネントモデルに由来しており、最も信頼性が高いのはSTA対応スレッド上です、これで現代ASP.NET Coreスタックの非同期/MTAホスティングが複雑になります。
複雑なAPI: ServerTextControlのコンテキスト管理に加え、個別のStringStreamType / BinaryStreamType / StreamType列挙体と選択駆動のドキュメントモデルが、単純なPDF生成タスクに対するオーバーヘッドを追加します。
コスト比較
| アスペクト | TX Text Control .NET Server | IronPDF |
|---|---|---|
| 単独開発者 | $4,198 永続 + 1年サポート | 一回限りの開発者ライセンス |
| チーム4人 | $8,398 永続 + 1年サポート | 1席あたりのコストを削減 |
| 年間更新 | リストの約40% (約$1,698/開発者/年) | オプションサポート |
| サーバーランタイム | プロダクションには別のランタイムライセンスが必要 | 不要 |
| UIコンポーネント | バンドルされたDOCXエディタサーフェス | PDFフォーカス |
IronPDFとTextControlの比較:機能の比較
アーキテクチャの違いを理解することは、技術的な意思決定者が移行への投資を評価するのに役立ちます:
| フィーチャー | TXテキストコントロール | IronPDF |
|---|---|---|
| 主な対象 | DOCX / ワードプロセッシング | PDF生成 |
| ライセンス費用 (単一開発者) | $4,198 永続 + 1年 約40%/年更新 | 一回限りの開発者ライセンス |
| PDF生成 | ワードプロセッシングエンジンのエクスポートパス | コア機能 |
| サーバーランタイムライセンス | プロダクションに必要 | 不要 |
| スレッディング | ASP.NETにおけるSTA依存 | STA要件なし |
| HTML/CSSレンダリング | ワードプロセッシングパイプラインを介したHTMLインポート | Chromium HTML5/CSS3 |
| HTMLからPDFへ | はい(二次) | はい(プライマリ) |
| CSSサポート | 制限的 | 完全なCSS3 |
| JavaScript | 制限的 | フルES2024 |
| URLからPDFへ | 複雑なセットアップ | ネイティブ |
| ヘッダー/フッター | 複雑なAPI | シンプルなHTML |
| メールマージ | 独自仕様 | HTMLテンプレート |
| PDF/A | はい | はい |
| パスワード保護 | はい | はい |
| デジタル署名 | はい | はい |
| PDFのマージ | 制限的 | はい |
| PDFの分割 | 制限的 | はい |
| コンテキスト管理 | 必須 | 不要 |
| クロスプラットフォーム | Windowsに特化 | Windows / Linux / macOS / Docker |
クイックスタートTextControlからIronPDFへの移行
これらの基本的なステップを踏めば、すぐにでも移行を開始できます。
ステップ 1: NuGet パッケージを置き換える
TX Text Controlのヘッドレスサーバーランタイムは単一の公開NuGetパッケージとして配布されず、公開パッケージはServerTextControlランタイムはライセンスされたWindowsインストーラー/MSIやベンダーのプライベートNuGetフィードを介して提供されます。 削除は通常、それらのインストーラーで配布されたパッケージおよびTXTextControl.Webをアンインストールし、MSIをアンインストールすることを意味します。
# RemoveTXテキストコントロールpackages (names depend on which were installed
# from the licensed installer / private feed / public NuGet)
dotnet remove package TXTextControl.Web
# Then installIronPDF(single self-contained package)
dotnet add package IronPdf
ステップ 2: 名前空間の更新
TextControlの名前空間をIronPDFの名前空間と置き換えます:
// Before (TextControl)
using TXTextControl;
using TXTextControl.DocumentServer;
// After (IronPDF)
using IronPdf;Imports TXTextControl
Imports TXTextControl.DocumentServer
' After (IronPDF)
Imports IronPdfImports TXTextControl
Imports TXTextControl.DocumentServer
' After (IronPDF)
Imports IronPdfステップ 3: ライセンスの初期化
アプリケーション起動時のライセンス初期化を追加します:
IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY";IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY";IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY"IronPdf.License.LicenseKey = "YOUR-LICENSE-KEY"コード移行の例
HTML を PDF に変換する
最も一般的な使用例は、これら for .NET PDFライブラリのアーキテクチャの違いを示しています。
TextControlのアプローチ:
// NuGet: Install-Package TXTextControl.Server
using TXTextControl;
using System.IO;
namespace TextControlExample
{
class Program
{
static void Main(string[] args)
{
using (ServerTextControl textControl = new ServerTextControl())
{
textControl.Create();
string html = "<html><body><h1>Hello World</h1><p>This is a PDF document.</p></body></html>";
textControl.Load(html, StringStreamType.HTMLFormat);
textControl.Save("output.pdf", StreamType.AdobePDF);
}
}
}
}// NuGet: Install-Package TXTextControl.Server
using TXTextControl;
using System.IO;
namespace TextControlExample
{
class Program
{
static void Main(string[] args)
{
using (ServerTextControl textControl = new ServerTextControl())
{
textControl.Create();
string html = "<html><body><h1>Hello World</h1><p>This is a PDF document.</p></body></html>";
textControl.Load(html, StringStreamType.HTMLFormat);
textControl.Save("output.pdf", StreamType.AdobePDF);
}
}
}
}Imports TXTextControl
Imports System.IO
Namespace TextControlExample
Class Program
Shared Sub Main(ByVal args As String())
Using textControl As New ServerTextControl()
textControl.Create()
Dim html As String = "<html><body><h1>Hello World</h1><p>This is a PDF document.</p></body></html>"
textControl.Load(html, StringStreamType.HTMLFormat)
textControl.Save("output.pdf", StreamType.AdobePDF)
End Using
End Sub
End Class
End NamespaceImports TXTextControl
Imports System.IO
Namespace TextControlExample
Class Program
Shared Sub Main(ByVal args As String())
Using textControl As New ServerTextControl()
textControl.Create()
Dim html As String = "<html><body><h1>Hello World</h1><p>This is a PDF document.</p></body></html>"
textControl.Load(html, StringStreamType.HTMLFormat)
textControl.Save("output.pdf", StreamType.AdobePDF)
End Using
End Sub
End Class
End NamespaceIronPDFのアプローチ:
// NuGet: Install-Package IronPdf
using IronPdf;
namespace IronPdfExample
{
class Program
{
static void Main(string[] args)
{
var renderer = new ChromePdfRenderer();
string html = "<html><body><h1>Hello World</h1><p>This is a PDF document.</p></body></html>";
var pdf = renderer.RenderHtmlAsPdf(html);
pdf.SaveAs("output.pdf");
}
}
}// NuGet: Install-Package IronPdf
using IronPdf;
namespace IronPdfExample
{
class Program
{
static void Main(string[] args)
{
var renderer = new ChromePdfRenderer();
string html = "<html><body><h1>Hello World</h1><p>This is a PDF document.</p></body></html>";
var pdf = renderer.RenderHtmlAsPdf(html);
pdf.SaveAs("output.pdf");
}
}
}' NuGet: Install-Package IronPdf
Imports IronPdf
Namespace IronPdfExample
Class Program
Shared Sub Main(args As String())
Dim renderer = New ChromePdfRenderer()
Dim html As String = "<html><body><h1>Hello World</h1><p>This is a PDF document.</p></body></html>"
Dim pdf = renderer.RenderHtmlAsPdf(html)
pdf.SaveAs("output.pdf")
End Sub
End Class
End Namespace' NuGet: Install-Package IronPdf
Imports IronPdf
Namespace IronPdfExample
Class Program
Shared Sub Main(args As String())
Dim renderer = New ChromePdfRenderer()
Dim html As String = "<html><body><h1>Hello World</h1><p>This is a PDF document.</p></body></html>"
Dim pdf = renderer.RenderHtmlAsPdf(html)
pdf.SaveAs("output.pdf")
End Sub
End Class
End NamespaceTextControlバージョンでは、StreamType.AdobePDFで保存する必要があります。 リソースを適切に破棄するためには、usingブロックが必須です。
IronPDFはコンテキスト管理を完全に排除します。 ChromePdfRendererは初期化手続き不要で、作成し、HTMLをレンダリングし、保存します。 このようにアーキテクチャを単純化することで、認識負荷や潜在的なリソース管理のバグを軽減します。
高度なHTMLからPDFへのシナリオについては、HTMLからPDFへの変換ガイドをご覧ください。
複数のPDFをマージする
PDFのマージは、これらのライブラリ間のもう1つの重要な複雑性の違いを明らかにします。
TextControlのアプローチ:
// NuGet: Install-Package TXTextControl.Server
using TXTextControl;
using System.IO;
namespace TextControlExample
{
class Program
{
static void Main(string[] args)
{
using (ServerTextControl textControl = new ServerTextControl())
{
textControl.Create();
byte[] pdf1 = File.ReadAllBytes("document1.pdf");
textControl.Load(pdf1, BinaryStreamType.AdobePDF);
byte[] pdf2 = File.ReadAllBytes("document2.pdf");
textControl.Append(pdf2, BinaryStreamType.AdobePDF, AppendSettings.StartWithNewSection);
textControl.Save("merged.pdf", StreamType.AdobePDF);
}
}
}
}// NuGet: Install-Package TXTextControl.Server
using TXTextControl;
using System.IO;
namespace TextControlExample
{
class Program
{
static void Main(string[] args)
{
using (ServerTextControl textControl = new ServerTextControl())
{
textControl.Create();
byte[] pdf1 = File.ReadAllBytes("document1.pdf");
textControl.Load(pdf1, BinaryStreamType.AdobePDF);
byte[] pdf2 = File.ReadAllBytes("document2.pdf");
textControl.Append(pdf2, BinaryStreamType.AdobePDF, AppendSettings.StartWithNewSection);
textControl.Save("merged.pdf", StreamType.AdobePDF);
}
}
}
}' NuGet: Install-Package TXTextControl.Server
Imports TXTextControl
Imports System.IO
Namespace TextControlExample
Class Program
Shared Sub Main(ByVal args() As String)
Using textControl As New ServerTextControl()
textControl.Create()
Dim pdf1 As Byte() = File.ReadAllBytes("document1.pdf")
textControl.Load(pdf1, BinaryStreamType.AdobePDF)
Dim pdf2 As Byte() = File.ReadAllBytes("document2.pdf")
textControl.Append(pdf2, BinaryStreamType.AdobePDF, AppendSettings.StartWithNewSection)
textControl.Save("merged.pdf", StreamType.AdobePDF)
End Using
End Sub
End Class
End Namespace' NuGet: Install-Package TXTextControl.Server
Imports TXTextControl
Imports System.IO
Namespace TextControlExample
Class Program
Shared Sub Main(ByVal args() As String)
Using textControl As New ServerTextControl()
textControl.Create()
Dim pdf1 As Byte() = File.ReadAllBytes("document1.pdf")
textControl.Load(pdf1, BinaryStreamType.AdobePDF)
Dim pdf2 As Byte() = File.ReadAllBytes("document2.pdf")
textControl.Append(pdf2, BinaryStreamType.AdobePDF, AppendSettings.StartWithNewSection)
textControl.Save("merged.pdf", StreamType.AdobePDF)
End Using
End Sub
End Class
End NamespaceIronPDFのアプローチ:
// NuGet: Install-Package IronPdf
using IronPdf;
namespace IronPdfExample
{
class Program
{
static void Main(string[] args)
{
var pdf1 = PdfDocument.FromFile("document1.pdf");
var pdf2 = PdfDocument.FromFile("document2.pdf");
var merged = PdfDocument.Merge(pdf1, pdf2);
merged.SaveAs("merged.pdf");
}
}
}// NuGet: Install-Package IronPdf
using IronPdf;
namespace IronPdfExample
{
class Program
{
static void Main(string[] args)
{
var pdf1 = PdfDocument.FromFile("document1.pdf");
var pdf2 = PdfDocument.FromFile("document2.pdf");
var merged = PdfDocument.Merge(pdf1, pdf2);
merged.SaveAs("merged.pdf");
}
}
}' NuGet: Install-Package IronPdf
Imports IronPdf
Namespace IronPdfExample
Class Program
Shared Sub Main(ByVal args As String())
Dim pdf1 = PdfDocument.FromFile("document1.pdf")
Dim pdf2 = PdfDocument.FromFile("document2.pdf")
Dim merged = PdfDocument.Merge(pdf1, pdf2)
merged.SaveAs("merged.pdf")
End Sub
End Class
End Namespace' NuGet: Install-Package IronPdf
Imports IronPdf
Namespace IronPdfExample
Class Program
Shared Sub Main(ByVal args As String())
Dim pdf1 = PdfDocument.FromFile("document1.pdf")
Dim pdf2 = PdfDocument.FromFile("document2.pdf")
Dim merged = PdfDocument.Merge(pdf1, pdf2)
merged.SaveAs("merged.pdf")
End Sub
End Class
End NamespaceTextControlでは、ファイルをバイト配列に読み込み、AppendSettings.StartWithNewSectionと共に呼び出してドキュメントを結合する必要があります。 IronPDFのPdfDocument.Merge()メソッドは1つの明示的な呼び出しで全てを処理します。
選択的なページ抽出を含む高度なマージシナリオについては、PDFのマージと分割ガイドを参照してください。
ヘッダーとフッターの追加
動的なページ番号を持つヘッダーとフッターは、APIの複雑さの違いを示しています。
TextControlのアプローチ:
// NuGet: Install-Package TXTextControl.Server
using TXTextControl;
using System.IO;
namespace TextControlExample
{
class Program
{
static void Main(string[] args)
{
using (ServerTextControl textControl = new ServerTextControl())
{
textControl.Create();
string html = "<html><body><h1>Document Content</h1><p>Main body text.</p></body></html>";
textControl.Load(html, StringStreamType.HTMLFormat);
HeaderFooter header = new HeaderFooter(HeaderFooterType.Header);
header.Text = "Document Header";
textControl.Sections[0].HeadersAndFooters.Add(header);
HeaderFooter footer = new HeaderFooter(HeaderFooterType.Footer);
footer.Text = "Page {page} of {numpages}";
textControl.Sections[0].HeadersAndFooters.Add(footer);
textControl.Save("output.pdf", StreamType.AdobePDF);
}
}
}
}// NuGet: Install-Package TXTextControl.Server
using TXTextControl;
using System.IO;
namespace TextControlExample
{
class Program
{
static void Main(string[] args)
{
using (ServerTextControl textControl = new ServerTextControl())
{
textControl.Create();
string html = "<html><body><h1>Document Content</h1><p>Main body text.</p></body></html>";
textControl.Load(html, StringStreamType.HTMLFormat);
HeaderFooter header = new HeaderFooter(HeaderFooterType.Header);
header.Text = "Document Header";
textControl.Sections[0].HeadersAndFooters.Add(header);
HeaderFooter footer = new HeaderFooter(HeaderFooterType.Footer);
footer.Text = "Page {page} of {numpages}";
textControl.Sections[0].HeadersAndFooters.Add(footer);
textControl.Save("output.pdf", StreamType.AdobePDF);
}
}
}
}' NuGet: Install-Package TXTextControl.Server
Imports TXTextControl
Imports System.IO
Namespace TextControlExample
Module Program
Sub Main(args As String())
Using textControl As New ServerTextControl()
textControl.Create()
Dim html As String = "<html><body><h1>Document Content</h1><p>Main body text.</p></body></html>"
textControl.Load(html, StringStreamType.HTMLFormat)
Dim header As New HeaderFooter(HeaderFooterType.Header)
header.Text = "Document Header"
textControl.Sections(0).HeadersAndFooters.Add(header)
Dim footer As New HeaderFooter(HeaderFooterType.Footer)
footer.Text = "Page {page} of {numpages}"
textControl.Sections(0).HeadersAndFooters.Add(footer)
textControl.Save("output.pdf", StreamType.AdobePDF)
End Using
End Sub
End Module
End Namespace' NuGet: Install-Package TXTextControl.Server
Imports TXTextControl
Imports System.IO
Namespace TextControlExample
Module Program
Sub Main(args As String())
Using textControl As New ServerTextControl()
textControl.Create()
Dim html As String = "<html><body><h1>Document Content</h1><p>Main body text.</p></body></html>"
textControl.Load(html, StringStreamType.HTMLFormat)
Dim header As New HeaderFooter(HeaderFooterType.Header)
header.Text = "Document Header"
textControl.Sections(0).HeadersAndFooters.Add(header)
Dim footer As New HeaderFooter(HeaderFooterType.Footer)
footer.Text = "Page {page} of {numpages}"
textControl.Sections(0).HeadersAndFooters.Add(footer)
textControl.Save("output.pdf", StreamType.AdobePDF)
End Using
End Sub
End Module
End NamespaceIronPDFのアプローチ:
// NuGet: Install-Package IronPdf
using IronPdf;
using IronPdf.Rendering;
namespace IronPdfExample
{
class Program
{
static void Main(string[] args)
{
var renderer = new ChromePdfRenderer();
string html = "<html><body><h1>Document Content</h1><p>Main body text.</p></body></html>";
var pdf = renderer.RenderHtmlAsPdf(html);
pdf.AddTextHeader("Document Header");
pdf.AddTextFooter("Page {page} of {total-pages}");
pdf.SaveAs("output.pdf");
}
}
}// NuGet: Install-Package IronPdf
using IronPdf;
using IronPdf.Rendering;
namespace IronPdfExample
{
class Program
{
static void Main(string[] args)
{
var renderer = new ChromePdfRenderer();
string html = "<html><body><h1>Document Content</h1><p>Main body text.</p></body></html>";
var pdf = renderer.RenderHtmlAsPdf(html);
pdf.AddTextHeader("Document Header");
pdf.AddTextFooter("Page {page} of {total-pages}");
pdf.SaveAs("output.pdf");
}
}
}' NuGet: Install-Package IronPdf
Imports IronPdf
Imports IronPdf.Rendering
Namespace IronPdfExample
Module Program
Sub Main(args As String())
Dim renderer = New ChromePdfRenderer()
Dim html As String = "<html><body><h1>Document Content</h1><p>Main body text.</p></body></html>"
Dim pdf = renderer.RenderHtmlAsPdf(html)
pdf.AddTextHeader("Document Header")
pdf.AddTextFooter("Page {page} of {total-pages}")
pdf.SaveAs("output.pdf")
End Sub
End Module
End Namespace' NuGet: Install-Package IronPdf
Imports IronPdf
Imports IronPdf.Rendering
Namespace IronPdfExample
Module Program
Sub Main(args As String())
Dim renderer = New ChromePdfRenderer()
Dim html As String = "<html><body><h1>Document Content</h1><p>Main body text.</p></body></html>"
Dim pdf = renderer.RenderHtmlAsPdf(html)
pdf.AddTextHeader("Document Header")
pdf.AddTextFooter("Page {page} of {total-pages}")
pdf.SaveAs("output.pdf")
End Sub
End Module
End NamespaceTextControlでは、特定のHeadersAndFootersコレクションに追加する必要があります。 IronPDFは単純なプレースホルダー構文を用いたTextHeaderFooter経由で)提供します。
HTMLベースのヘッダーに完全なスタイリング制御を行うために、IronPDFはHtmlHeaderFooterもサポートしています。
renderer.RenderingOptions.HtmlHeader = new HtmlHeaderFooter
{
HtmlFragment = @"
<div style='width: 100%; text-align: center; font-size: 12pt;'>
Company Report
</div>",
MaxHeight = 30
};
renderer.RenderingOptions.HtmlFooter = new HtmlHeaderFooter
{
HtmlFragment = @"
<div style='width: 100%; text-align: right; font-size: 10pt;'>
Page {page} of {total-pages}
</div>",
MaxHeight = 25
};renderer.RenderingOptions.HtmlHeader = new HtmlHeaderFooter
{
HtmlFragment = @"
<div style='width: 100%; text-align: center; font-size: 12pt;'>
Company Report
</div>",
MaxHeight = 30
};
renderer.RenderingOptions.HtmlFooter = new HtmlHeaderFooter
{
HtmlFragment = @"
<div style='width: 100%; text-align: right; font-size: 10pt;'>
Page {page} of {total-pages}
</div>",
MaxHeight = 25
};renderer.RenderingOptions.HtmlHeader = New HtmlHeaderFooter With {
.HtmlFragment = "
<div style='width: 100%; text-align: center; font-size: 12pt;'>
Company Report
</div>",
.MaxHeight = 30
}
renderer.RenderingOptions.HtmlFooter = New HtmlHeaderFooter With {
.HtmlFragment = "
<div style='width: 100%; text-align: right; font-size: 10pt;'>
Page {page} of {total-pages}
</div>",
.MaxHeight = 25
}renderer.RenderingOptions.HtmlHeader = New HtmlHeaderFooter With {
.HtmlFragment = "
<div style='width: 100%; text-align: center; font-size: 12pt;'>
Company Report
</div>",
.MaxHeight = 30
}
renderer.RenderingOptions.HtmlFooter = New HtmlHeaderFooter With {
.HtmlFragment = "
<div style='width: 100%; text-align: right; font-size: 10pt;'>
Page {page} of {total-pages}
</div>",
.MaxHeight = 25
}ヘッダーとフッターのオプションについては、headers and footers documentationをご覧ください。
TextControl APIからIronPDFへのマッピングリファレンス
このマッピングは、APIと同等のものを直接示すことで、移行を加速します:
| TXテキストコントロール | IronPDF |
|---|---|
ServerTextControl.Create() | new ChromePdfRenderer() |
tx.Load(html, StringStreamType.HTMLFormat) | renderer.RenderHtmlAsPdf(html) |
tx.Load(bytes, BinaryStreamType.AdobePDF) | PdfDocument.FromFile(...) / FromBinaryData(...) |
tx.Save(path, StreamType.AdobePDF) | pdf.SaveAs(path) |
tx.Append(bytes, BinaryStreamType.AdobePDF, AppendSettings.StartWithNewSection) | PdfDocument.Merge(a, b) |
SaveSettings.PDFAConformance | RenderingOptions.PdfAFormat |
DocumentServer.MailMerge | HTMLテンプレート + Razor |
HeaderFooter + Sections[i].HeadersAndFooters | HtmlHeaderFooter / TextHeaderFooter |
LoadSettings | RenderingOptions |
StreamType.AdobePDF | デフォルト出力 |
一般的な移行の問題と解決策
問題 1: ServerTextControl コンテキスト
TextControlでは、各操作にusingブロックが必要です。
ソリューション: IronPDFにはコンテキスト管理がありません:
// Just create and use
var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderHtmlAsPdf(html);// Just create and use
var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderHtmlAsPdf(html);' Just create and use
Dim renderer As New ChromePdfRenderer()
Dim pdf = renderer.RenderHtmlAsPdf(html)' Just create and use
Dim renderer As New ChromePdfRenderer()
Dim pdf = renderer.RenderHtmlAsPdf(html)課題2: StreamTypeの変換
TextControlは3つの異なる列挙体を使い分けています:文字列オーバーロードのStringStreamType、バイト[] オーバーロードのStreamTypeを用いて、異なる形式をロードし、PDFにエクスポートします。
ソリューション: IronPDFは中間フォーマット変換なしでHTMLを直接レンダリングします:
// No format conversion needed
var pdf = renderer.RenderHtmlAsPdf(html);// No format conversion needed
var pdf = renderer.RenderHtmlAsPdf(html);Dim pdf = renderer.RenderHtmlAsPdf(html)Dim pdf = renderer.RenderHtmlAsPdf(html)課題3:DOCXテンプレート
TextControlは、メールマージのテンプレートにDOCXファイルを使用します。
ソリューション: C#文字列補間またはRazorを使ってHTMLテンプレートに変換する:
var data = new { CustomerName = "John Doe", InvoiceNumber = "12345", Total = "$1,500.00" };
var html = $@"
<html>
<head>
<style>
body {{font-family: Arial; padding: 40px;}}
h1 {{color: #333;}}
.total {{font-size: 24px; color: green;}}
</style>
</head>
<body>
<h1>Invoice #{data.InvoiceNumber}</h1>
<p>Customer: {data.CustomerName}</p>
<p class='total'>Total: {data.Total}</p>
</body>
</html>";
var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderHtmlAsPdf(html);
pdf.SaveAs("invoice.pdf");var data = new { CustomerName = "John Doe", InvoiceNumber = "12345", Total = "$1,500.00" };
var html = $@"
<html>
<head>
<style>
body {{font-family: Arial; padding: 40px;}}
h1 {{color: #333;}}
.total {{font-size: 24px; color: green;}}
</style>
</head>
<body>
<h1>Invoice #{data.InvoiceNumber}</h1>
<p>Customer: {data.CustomerName}</p>
<p class='total'>Total: {data.Total}</p>
</body>
</html>";
var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderHtmlAsPdf(html);
pdf.SaveAs("invoice.pdf");Dim data = New With {Key .CustomerName = "John Doe", Key .InvoiceNumber = "12345", Key .Total = "$1,500.00"}
Dim html = $"
<html>
<head>
<style>
body {{font-family: Arial; padding: 40px;}}
h1 {{color: #333;}}
.total {{font-size: 24px; color: green;}}
</style>
</head>
<body>
<h1>Invoice #{data.InvoiceNumber}</h1>
<p>Customer: {data.CustomerName}</p>
<p class='total'>Total: {data.Total}</p>
</body>
</html>"
Dim renderer = New ChromePdfRenderer()
Dim pdf = renderer.RenderHtmlAsPdf(html)
pdf.SaveAs("invoice.pdf")Dim data = New With {Key .CustomerName = "John Doe", Key .InvoiceNumber = "12345", Key .Total = "$1,500.00"}
Dim html = $"
<html>
<head>
<style>
body {{font-family: Arial; padding: 40px;}}
h1 {{color: #333;}}
.total {{font-size: 24px; color: green;}}
</style>
</head>
<body>
<h1>Invoice #{data.InvoiceNumber}</h1>
<p>Customer: {data.CustomerName}</p>
<p class='total'>Total: {data.Total}</p>
</body>
</html>"
Dim renderer = New ChromePdfRenderer()
Dim pdf = renderer.RenderHtmlAsPdf(html)
pdf.SaveAs("invoice.pdf")問題4: ASP.NETでのSTA-Affinity
TextControl ServerTextControlは歴史的にSTA COMスタイルのコンポーネントモデルに遡り、STA互換のスレッド上にホストされると最も信頼性があります(例: 古典的なWebフォームの[ASPCOMPAT]や、ASP.NET Coreで専用STAスレッド/キューで呼び出しをラップする)。 それをMTAワーカースレッドと自由に混在させると、負荷時に時折スレッドアフィニティエラーが発生することがあります。
解決策: IronPDFにはSTA要件がなく、MTAワーカースレッド、非同期コントローラ、および.NET 6/7/8/9のLinuxコンテナ内で修正なしに実行されます。
TextControl移行チェックリスト
マイグレーション前のタスク
コードベースを監査して、すべてのTextControlの使い方を特定します:
grep -r "using TXTextControl" --include="*.cs" .
grep -r "ServerTextControl\|Load\|Save" --include="*.cs" .
HTMLに変換するためのメールマージテンプレートを文書化すること。 HtmlHeaderFooterを使用した実装におけるヘッダー/フッターの要件に注意してください。 代替ソリューションが必要と思われるDOCX編集機能を特定してください。
コード更新タスク
1.TX Text Control NuGetパッケージの削除
2.IronPDFNuGet パッケージをインストールします
3. Create()呼び出しは不要です)
4. RenderHtmlAsPdfに変換します
5.文字列補間またはRazorを使用したメールマージからHTMLテンプレートへの変換
6. ヘッダー/フッターをAddTextFooterを使用するように更新します
7. RenderingOptionsを使用してページ設定を簡素化します
8.起動時のライセンス初期化を追加
移行後のテスト
移行後、これらの点を検証してください:
- すべてのドキュメントテンプレートが正しくレンダリングされることをテスト
- 必要であれば、PDF/Aコンプライアンスを検証すること。
- パスワード保護機能のテスト
- すべてのページにヘッダー/フッターが表示されていることを確認する。
- MTAワーカースレッドとLinuxコンテナでのASP.NET Coreホスティングを検証 - IronPDFにはSTAアフィニティ要件がありません
IronPDFに移行する主な利点
TextControlからIronPDFに移行することで、PDF生成に特化したチームにはいくつかの利点があります:
PDF-ファーストアーキテクチャ: IronPDFはPDF生成に特化しており、最新のHTML5およびCSS3標準を利用してドキュメント作成およびレンダリング能力を提供します。
コスト効率: IronPDFの一回限りの開発者あたりの価格は、TX Text Control .NET Serverの$4,198永続 + 1年ライセンスと更新モデル(約40%/年)と比較して有利です。特に別々のサーバーランタイムライセンスが考慮されると。
STA・アフィニティ不要: IronPDFはSTA互換ホスティングの考慮を必要とせず、ASP.NET Core、非同期コントローラ、およびLinuxコンテナの標準MTAワーカースレッドで実行されます。
コンテキスト管理なし: StringStreamType / BinaryStreamType / StreamType)ロード/保存ダンスを排除します - ChromePdfRendererはステートレスです。
最新のレンダリングエンジン: IronPDFはワードプロセッシングエンジンのHTMLインポートパスではなく、最新のHTML5/CSS3/JavaScript標準にターゲットを合わせたChromiumベースのレンダリングを行います。
Curtis Chauは、カールトン大学でコンピュータサイエンスの学士号を取得し、Node.js、TypeScript、JavaScript、およびReactに精通したフロントエンド開発を専門としています。直感的で美しいユーザーインターフェースを作成することに情熱を持ち、Curtisは現代のフレームワークを用いた開発や、構造の良い視覚的に魅力的なマニュアルの作成を楽しんでいます。
関連する記事


