PDFを記入可能にする方法
HTMLをPDFに変換することは、レポートや請求書の作成、ドキュメントの生成など、多くの現代のソフトウェア開発ワークフローで重要なタスクです。 C#開発者として、このプロセスを効率化するためのライブラリがいくつか利用可能です。
この記事では、.NETエコシステム内の2つの人気のあるライブラリであるIronPDFとiTextを比較します。 両方のライブラリは強力な機能を提供しますが、使いやすさ、PDF作成ツール、CSSスタイリングのサポート、ライセンスなどの重要な点で異なります。 初心者でも経験豊富な開発者でも、このガイドは基本機能を理解し、プロジェクト要件に基づいてどれが最適かを判断する手助けをします。
- 一緒に進むことを希望しますか? IronPDFの強力な機能を自分で探求するために、IronPDF無料トライアルをダウンロードしてください。*
トップライブラリの比較:iTextとIronPDF
iTextもIronPDFも開発者にC#でのHTMLからPDFへの変換ツールを提供します。 ただし、それぞれに独自の強みと弱点があります。
-
iTextは長らく存在しているオープンソースのライブラリです。柔軟性と広範なカスタマイズオプションを提供しますが、特に高度なHTMLやCSSのレンダリングに取り組む場合、設定と使用がやや複雑です。 しかし、iTextはレガシープロダクトであり、現在はセキュリティ関連の更新のみが行われています。
-
一方、IronPDFは、Iron Softwareによって開発された商用製品です。 使いやすいインターフェース、堅牢なCSSサポート、使いやすさで知られています。 C#アプリケーションとのシームレスな統合を提供し、品質を犠牲にすることなく迅速で効率的なPDF生成が必要な開発者にとって最適な選択肢です。
これら2つのライブラリを使ってHTMLをPDFフォーマットに変換する方法を掘り下げる前に、まずこれらの2つのライブラリがCSSとJavaScriptを多用するウェブページ/HTMLコンテンツをPDFドキュメントに変換する際の違いを示す基本的な例を見てみましょう。

結果のPDFドキュメントから見ると、iTextは提供されたURLから生のHTMLコンテンツを処理することしかできませんが、IronPDFはオリジナルのCSSレイアウトとスタイリングを維持し、生成されたPDFドキュメントが元のウェブページに近い形であることを保証します。
ステップバイステップインストールガイド
iTextのセットアップ
- NuGetコンソールからインストール:iTextを使用するには、NuGetから直接インストールできます。 Visual Studioプロジェクトを開き、NuGetパッケージマネージャーに移動し、次のコマンドを実行してください。

- NuGetパッケージマネージャー経由でインストール: 代わりに、ソリューション画面のNuGetパッケージマネージャーを介してインストールすることもできます。 これを行うには、"ツール > NuGetパッケージマネージャ > ソリューションのNuGetパッケージを管理"へ移動します。

次に、iTextライブラリを検索し、"インストール"をクリックします。

- リファレンスの追加: インストール後、特にHTMLからPDFへの変換に関連する必要なリファレンスをプロジェクトに追加します。
using iTextSharp.text.pdf;
using iTextSharp.text.html.simpleparser;Imports iTextSharp.text.pdf
Imports iTextSharp.text.html.simpleparserImports iTextSharp.text.pdf
Imports iTextSharp.text.html.simpleparserIronPDFのセットアップ
- NuGetコンソール経由でインストール: IronPDFを使用し始めるには、NuGetから直接インストールできます。 Visual Studioプロジェクトを開き、NuGetパッケージマネージャーに移動し、次のコマンドを実行してください。
-
NuGetパッケージマネージャーからインストール: または、ソリューション画面のNuGetパッケージマネージャーから、iTextと同様にインストールできます。 ただし、この時点で、IronPDFを検索し、"インストール"をクリックしてください。

-
リファレンスの追加: インストール後、プロジェクトにIronPDFをインポートします。
using IronPdf;using IronPdf;Imports IronPdfImports IronPdfIronPDFは商業利用/開発外での使用にはライセンスキーが必要であることを覚えておいてください。
HTMLからPDFへの変換の実装
iTextの使用
iTextがセットアップされると、プロジェクト内にitextsharp.xmlworkerパッケージがインストールされていることを確認し、HTMLコンテンツからPDFを作成することができます。 しかし、より複雑なHTML、特にCSSスタイルが関与している場合には、課題に直面するでしょう。 iTextは、IronPDFと比較して完璧なスタイリングを得るために追加の労力を必要とする傾向があります。 iTextは基本的なHTML/CSS2のみをサポートしていることを忘れないでください(フレックスボックス、グリッド、制限付きCSSを含まない)。
using System;
using System.IO;
using iTextSharp.text;
using iTextSharp.text.pdf;
using iTextSharp.tool.xml;
// Register provider for specific code pages
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
// Define HTML content with CSS styling
string html = @"
<html>
<head>
<style>
body { font-family: Arial; color: #333; }
h1 { background: #3498db; color: #fff; padding: 10px; }
table { width: 100%; border-collapse: collapse; margin-top: 15px; }
th, td { border: 1px solid #ccc; padding: 6px; }
th { background: #2980b9; color: #fff; }
.footer { margin-top: 20px; font-size: 12px; color: #777; text-align: center; }
</style>
</head>
<body>
<h1>April Report</h1>
<p>Here’s a quick overview of this month’s performance metrics.</p>
<table>
<tr><th>Metric</th><th>Value</th></tr>
<tr><td>Features</td><td>12</td></tr>
<tr><td>Bugs Fixed</td><td>89</td></tr>
</table>
<p class='footer'>Generated by iTextSharp</p>
</body>
</html>";
// Create PDF from HTML content
using (FileStream stream = new FileStream("report.pdf", FileMode.Create))
{
Document pdfDoc = new Document(PageSize.A4, 25, 25, 30, 30);
PdfWriter writer = PdfWriter.GetInstance(pdfDoc, stream);
pdfDoc.Open();
using (StringReader sr = new StringReader(html))
{
// Use XMLWorkerHelper to parse and add HTML content to the PDF document
XMLWorkerHelper.GetInstance().ParseXHtml(writer, pdfDoc, sr);
}
pdfDoc.Close();
writer.Close();
}
Console.WriteLine("PDF generation completed successfully.");using System;
using System.IO;
using iTextSharp.text;
using iTextSharp.text.pdf;
using iTextSharp.tool.xml;
// Register provider for specific code pages
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
// Define HTML content with CSS styling
string html = @"
<html>
<head>
<style>
body { font-family: Arial; color: #333; }
h1 { background: #3498db; color: #fff; padding: 10px; }
table { width: 100%; border-collapse: collapse; margin-top: 15px; }
th, td { border: 1px solid #ccc; padding: 6px; }
th { background: #2980b9; color: #fff; }
.footer { margin-top: 20px; font-size: 12px; color: #777; text-align: center; }
</style>
</head>
<body>
<h1>April Report</h1>
<p>Here’s a quick overview of this month’s performance metrics.</p>
<table>
<tr><th>Metric</th><th>Value</th></tr>
<tr><td>Features</td><td>12</td></tr>
<tr><td>Bugs Fixed</td><td>89</td></tr>
</table>
<p class='footer'>Generated by iTextSharp</p>
</body>
</html>";
// Create PDF from HTML content
using (FileStream stream = new FileStream("report.pdf", FileMode.Create))
{
Document pdfDoc = new Document(PageSize.A4, 25, 25, 30, 30);
PdfWriter writer = PdfWriter.GetInstance(pdfDoc, stream);
pdfDoc.Open();
using (StringReader sr = new StringReader(html))
{
// Use XMLWorkerHelper to parse and add HTML content to the PDF document
XMLWorkerHelper.GetInstance().ParseXHtml(writer, pdfDoc, sr);
}
pdfDoc.Close();
writer.Close();
}
Console.WriteLine("PDF generation completed successfully.");Imports System
Imports System.IO
Imports iTextSharp.text
Imports iTextSharp.text.pdf
Imports iTextSharp.tool.xml
' Register provider for specific code pages
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance)
' Define HTML content with CSS styling
Dim html As String = "
<html>
<head>
<style>
body { font-family: Arial; color: #333; }
h1 { background: #3498db; color: #fff; padding: 10px; }
table { width: 100%; border-collapse: collapse; margin-top: 15px; }
th, td { border: 1px solid #ccc; padding: 6px; }
th { background: #2980b9; color: #fff; }
.footer { margin-top: 20px; font-size: 12px; color: #777; text-align: center; }
</style>
</head>
<body>
<h1>April Report</h1>
<p>Here’s a quick overview of this month’s performance metrics.</p>
<table>
<tr><th>Metric</th><th>Value</th></tr>
<tr><td>Features</td><td>12</td></tr>
<tr><td>Bugs Fixed</td><td>89</td></tr>
</table>
<p class='footer'>Generated by iTextSharp</p>
</body>
</html>"
' Create PDF from HTML content
Using stream As New FileStream("report.pdf", FileMode.Create)
Dim pdfDoc As New Document(PageSize.A4, 25, 25, 30, 30)
Dim writer As PdfWriter = PdfWriter.GetInstance(pdfDoc, stream)
pdfDoc.Open()
Using sr As New StringReader(html)
' Use XMLWorkerHelper to parse and add HTML content to the PDF document
XMLWorkerHelper.GetInstance().ParseXHtml(writer, pdfDoc, sr)
End Using
pdfDoc.Close()
writer.Close()
End Using
Console.WriteLine("PDF generation completed successfully.")Imports System
Imports System.IO
Imports iTextSharp.text
Imports iTextSharp.text.pdf
Imports iTextSharp.tool.xml
' Register provider for specific code pages
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance)
' Define HTML content with CSS styling
Dim html As String = "
<html>
<head>
<style>
body { font-family: Arial; color: #333; }
h1 { background: #3498db; color: #fff; padding: 10px; }
table { width: 100%; border-collapse: collapse; margin-top: 15px; }
th, td { border: 1px solid #ccc; padding: 6px; }
th { background: #2980b9; color: #fff; }
.footer { margin-top: 20px; font-size: 12px; color: #777; text-align: center; }
</style>
</head>
<body>
<h1>April Report</h1>
<p>Here’s a quick overview of this month’s performance metrics.</p>
<table>
<tr><th>Metric</th><th>Value</th></tr>
<tr><td>Features</td><td>12</td></tr>
<tr><td>Bugs Fixed</td><td>89</td></tr>
</table>
<p class='footer'>Generated by iTextSharp</p>
</body>
</html>"
' Create PDF from HTML content
Using stream As New FileStream("report.pdf", FileMode.Create)
Dim pdfDoc As New Document(PageSize.A4, 25, 25, 30, 30)
Dim writer As PdfWriter = PdfWriter.GetInstance(pdfDoc, stream)
pdfDoc.Open()
Using sr As New StringReader(html)
' Use XMLWorkerHelper to parse and add HTML content to the PDF document
XMLWorkerHelper.GetInstance().ParseXHtml(writer, pdfDoc, sr)
End Using
pdfDoc.Close()
writer.Close()
End Using
Console.WriteLine("PDF generation completed successfully.")出力PDFファイル

IronPDFを使用する
IronPDFはPDF生成プロセスを簡素化し、わずか数行のコードでHTMLコンテンツを新しいPDFドキュメントに簡単に変換できます。次のコードサンプルで実証されています。 これは、スタイリングに使用されるCSSファイル、HTML文字列、CSS/JavaScriptが多用されるウェブコンテンツを伴う高度なHTMLドキュメントでも動作します。
これは、インラインCSSを含むシンプルな例です:
using IronPdf;
class Program
{
static void Main()
{
// Define HTML content with inline CSS styling
var content = @"
<html>
<head>
<style>
body {
font-family: 'Segoe UI', sans-serif;
margin: 40px;
background-color: #f8f9fa;
}
h1 {
color: #2c3e50;
border-bottom: 2px solid #2980b9;
padding-bottom: 10px;
}
table {
width: 100%;
border-collapse: collapse;
margin-top: 20px;
}
table, th, td {
border: 1px solid #ccc;
}
th {
background-color: #2980b9;
color: white;
padding: 10px;
}
td {
padding: 10px;
background-color: #ecf0f1;
}
.footer {
margin-top: 40px;
text-align: center;
font-size: 0.9em;
color: #7f8c8d;
}
img {
width: 120px;
float: right;
}
</style>
</head>
<body>
<img src='https://ironpdf.com/img/svgs/iron-pdf-logo.svg' alt='Company Logo' />
<h1>Monthly Report - April 2025</h1>
<p>This report outlines performance statistics and key updates for the development team.</p>
<table>
<tr>
<th>Metric</th>
<th>Value</th>
<th>Change</th>
</tr>
<tr>
<td>Feature Releases</td>
<td>12</td>
<td style='color: green;'>+20%</td>
</tr>
<tr>
<td>Bugs Resolved</td>
<td>89</td>
<td style='color: green;'>+45%</td>
</tr>
<tr>
<td>Downtime</td>
<td>2 hrs</td>
<td style='color: red;'>+15%</td>
</tr>
</table>
<div class='footer'>
Generated with IronPDF | © 2025 DevCorp
</div>
</body>
</html>";
// Use ChromePdfRenderer to render the HTML content as a PDF
var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderHtmlAsPdf(content);
pdf.SaveAs("AdvancedStyledReport.pdf");
}
}using IronPdf;
class Program
{
static void Main()
{
// Define HTML content with inline CSS styling
var content = @"
<html>
<head>
<style>
body {
font-family: 'Segoe UI', sans-serif;
margin: 40px;
background-color: #f8f9fa;
}
h1 {
color: #2c3e50;
border-bottom: 2px solid #2980b9;
padding-bottom: 10px;
}
table {
width: 100%;
border-collapse: collapse;
margin-top: 20px;
}
table, th, td {
border: 1px solid #ccc;
}
th {
background-color: #2980b9;
color: white;
padding: 10px;
}
td {
padding: 10px;
background-color: #ecf0f1;
}
.footer {
margin-top: 40px;
text-align: center;
font-size: 0.9em;
color: #7f8c8d;
}
img {
width: 120px;
float: right;
}
</style>
</head>
<body>
<img src='https://ironpdf.com/img/svgs/iron-pdf-logo.svg' alt='Company Logo' />
<h1>Monthly Report - April 2025</h1>
<p>This report outlines performance statistics and key updates for the development team.</p>
<table>
<tr>
<th>Metric</th>
<th>Value</th>
<th>Change</th>
</tr>
<tr>
<td>Feature Releases</td>
<td>12</td>
<td style='color: green;'>+20%</td>
</tr>
<tr>
<td>Bugs Resolved</td>
<td>89</td>
<td style='color: green;'>+45%</td>
</tr>
<tr>
<td>Downtime</td>
<td>2 hrs</td>
<td style='color: red;'>+15%</td>
</tr>
</table>
<div class='footer'>
Generated with IronPDF | © 2025 DevCorp
</div>
</body>
</html>";
// Use ChromePdfRenderer to render the HTML content as a PDF
var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderHtmlAsPdf(content);
pdf.SaveAs("AdvancedStyledReport.pdf");
}
}Imports IronPdf
Friend Class Program
Shared Sub Main()
' Define HTML content with inline CSS styling
Dim content = "
<html>
<head>
<style>
body {
font-family: 'Segoe UI', sans-serif;
margin: 40px;
background-color: #f8f9fa;
}
h1 {
color: #2c3e50;
border-bottom: 2px solid #2980b9;
padding-bottom: 10px;
}
table {
width: 100%;
border-collapse: collapse;
margin-top: 20px;
}
table, th, td {
border: 1px solid #ccc;
}
th {
background-color: #2980b9;
color: white;
padding: 10px;
}
td {
padding: 10px;
background-color: #ecf0f1;
}
.footer {
margin-top: 40px;
text-align: center;
font-size: 0.9em;
color: #7f8c8d;
}
img {
width: 120px;
float: right;
}
</style>
</head>
<body>
<img src='https://ironpdf.com/img/svgs/iron-pdf-logo.svg' alt='Company Logo' />
<h1>Monthly Report - April 2025</h1>
<p>This report outlines performance statistics and key updates for the development team.</p>
<table>
<tr>
<th>Metric</th>
<th>Value</th>
<th>Change</th>
</tr>
<tr>
<td>Feature Releases</td>
<td>12</td>
<td style='color: green;'>+20%</td>
</tr>
<tr>
<td>Bugs Resolved</td>
<td>89</td>
<td style='color: green;'>+45%</td>
</tr>
<tr>
<td>Downtime</td>
<td>2 hrs</td>
<td style='color: red;'>+15%</td>
</tr>
</table>
<div class='footer'>
Generated with IronPDF | © 2025 DevCorp
</div>
</body>
</html>"
' Use ChromePdfRenderer to render the HTML content as a PDF
Dim renderer = New ChromePdfRenderer()
Dim pdf = renderer.RenderHtmlAsPdf(content)
pdf.SaveAs("AdvancedStyledReport.pdf")
End Sub
End ClassImports IronPdf
Friend Class Program
Shared Sub Main()
' Define HTML content with inline CSS styling
Dim content = "
<html>
<head>
<style>
body {
font-family: 'Segoe UI', sans-serif;
margin: 40px;
background-color: #f8f9fa;
}
h1 {
color: #2c3e50;
border-bottom: 2px solid #2980b9;
padding-bottom: 10px;
}
table {
width: 100%;
border-collapse: collapse;
margin-top: 20px;
}
table, th, td {
border: 1px solid #ccc;
}
th {
background-color: #2980b9;
color: white;
padding: 10px;
}
td {
padding: 10px;
background-color: #ecf0f1;
}
.footer {
margin-top: 40px;
text-align: center;
font-size: 0.9em;
color: #7f8c8d;
}
img {
width: 120px;
float: right;
}
</style>
</head>
<body>
<img src='https://ironpdf.com/img/svgs/iron-pdf-logo.svg' alt='Company Logo' />
<h1>Monthly Report - April 2025</h1>
<p>This report outlines performance statistics and key updates for the development team.</p>
<table>
<tr>
<th>Metric</th>
<th>Value</th>
<th>Change</th>
</tr>
<tr>
<td>Feature Releases</td>
<td>12</td>
<td style='color: green;'>+20%</td>
</tr>
<tr>
<td>Bugs Resolved</td>
<td>89</td>
<td style='color: green;'>+45%</td>
</tr>
<tr>
<td>Downtime</td>
<td>2 hrs</td>
<td style='color: red;'>+15%</td>
</tr>
</table>
<div class='footer'>
Generated with IronPDF | © 2025 DevCorp
</div>
</body>
</html>"
' Use ChromePdfRenderer to render the HTML content as a PDF
Dim renderer = New ChromePdfRenderer()
Dim pdf = renderer.RenderHtmlAsPdf(content)
pdf.SaveAs("AdvancedStyledReport.pdf")
End Sub
End Class出力PDFファイル

IronPDFを使用すると、上記のコード例で見られるように、正確なCSSスタイリングを持つ洗練されたPDFファイルを期待できます。これは、複雑なHTMLファイル、文字列などで作業する多くの開発者にとっての頼りになるものです。 単純なHTMLからPDFドキュメントへの変換タスクを超えて、IronPDFは高度なPDF操作タスクやPDFセキュリティが可能です。 これにより、それはオールインワンのPDFライブラリとして優れています。
重要な違いと競合環境
iTextとIronPDFの評価の際には、機能だけでなく競合状況も考慮することが重要です。 ApryseやAspose.PDFのような他の競合他社も同様のHTMLからPDFへのソリューションを提供していますが、価格や機能に関してはそれぞれのトレードオフがあります。
| 特徴 | IronPDF | iText | Apryse | Aspose.PDF |
|---|---|---|---|---|
| 使いやすさ | 高い | 中くらい | 高い | 中くらい |
| CSSサポート | Full | 部分的 | Full | 満杯 |
| ライセンス | Commercial | オープンソース | Commercial | コマーシャル |
| サポート | 優れた | コミュニティ | Premium | プレミアム |
| 価格 | From $999 | 無料/商業ライセンス | 見積もりベース | 年間1,679ドルから |
IronPDF は、現代のHTML5およびCSS3に対する包括的なサポートにより、今日のほとんどの開発者にとって重要です。 PDFドキュメントの操作、PDFドキュメント作成の制御、変換プロセスの容易さなどの拡張サポートにより、IronPDFは人気のあるPDFライブラリです。
結論と推奨事項
結論として、IronPDFとiTextの両方がC#でのHTMLからPDFへの変換に強力な機能を提供していますが、異なるタイプの開発者に対応しています。 オープンソースソリューションを探していて、強力なコミュニティサポートを求めるなら、iTextが適しているかもしれません。しかし、使いやすさ、強力なCSSサポート、商用ソリューションを必要とする開発者には、IronPDFがはるかに洗練された機能豊富な体験を提供します。 見積り書の自動生成、ブランド化されたPDFドキュメントの作成、またはウェブページ全体をPDFファイルに変換するツールをお探しなら、IronPDFが責任を持って処理します。
今日、IronPDFのユーザーフレンドリーな機能を試してみてください– 無料トライアル をダウンロードして、HTMLからPDFへの変換がどれほど簡単であるかを実際に体験してみましょう。
[[i: (iTextはその所有者の登録商標です。 このサイトは、iTextと提携しておらず、承認されてもおらず、後援されてもいません。 すべての製品名、ロゴ、およびブランドは各所有者の所有物です。 比較は情報提供のみを目的としており、執筆時点で公開されている情報を反映しています。)]]
Curtis Chauは、カールトン大学でコンピュータサイエンスの学士号を取得し、Node.js、TypeScript、JavaScript、およびReactに精通したフロントエンド開発を専門としています。直感的で美しいユーザーインターフェースを作成することに情熱を持ち、Curtisは現代のフレームワークを用いた開発や、構造の良い視覚的に魅力的なマニュアルの作成を楽しんでいます。