透かしなしで本番環境でテストしてください。
必要な場所で動作します。
30日間、完全に機能する製品をご利用いただけます。
数分で稼働させることができます。
製品トライアル期間中にサポートエンジニアリングチームへの完全アクセス
HTMLをPDFに変換することは、多くの現代のソフトウェア開発ワークフローで重要なタスクであり、レポートの生成、請求書、またはドキュメントの作成にとって重要です。 C#開発者として、このプロセスを効率化するためのライブラリがいくつか利用できます。
この記事では、.NET エコシステム内で最も人気のある2つのライブラリ、IronPDF と iTextSharp を比較します。 両方のライブラリは堅牢な機能を提供しますが、使いやすさ、PDF作成ツール、CSSスタイリングのサポート、ライセンスなどの重要な点で異なります。 初心者であれ、経験豊富な開発者であれ、このガイドは基本的な機能を理解し、ニーズとプロジェクトの要件に基づいて最適なものを選ぶ手助けをします。
一緒にフォローしたいですか? IronPDF 無料試用版をダウンロードして、IronPDF の強力な機能を自分で探ってみてください。
iTextSharp と IronPDF はどちらも、C#でのHTMLからPDFへの変換に必要なツールを開発者に提供します。 しかし、それぞれには独自の強みと弱みがあります。
IronPDFは、一方で、Iron Softwareによって開発された商用製品です。 それは、ユーザーフレンドリーなインターフェース、堅牢なCSSサポート、そして使いやすさで知られています。 これはC#アプリケーションとシームレスに統合され、品質を犠牲にすることなく迅速で効率的なPDF生成が必要な開発者にとって優れた選択肢となります。
これらの2つのライブラリを使用してHTMLをPDF形式に変換する方法を説明する前に、まず基本的な例の比較を見て、これらの2つのライブラリがどのようにしてCSSやJavaScriptを多用したウェブページ/HTMLコンテンツをPDFドキュメントに変換するかの違いを示します。
生成されたPDFドキュメントから分かるように、これはiTextSharpが提供されたURLからの生のHTMLコンテンツのみを処理できることを示していますが、IronPDFは元のCSSレイアウトとスタイルを保持し、生成されたPDFドキュメントが元のウェブページに非常に似たものとなることを保証します。
Install-Package iTextSharp
Install-Package iTextSharp
'INSTANT VB TODO TASK: The following line uses invalid syntax:
'Install-Package iTextSharp
NuGetパッケージマネージャーでインストール: 代わりに、それをソリューション画面用のNuGetパッケージマネージャーを通じてインストールすることができます。 これを行うには、「ツール > NuGet パッケージ マネージャー > ソリューションの NuGet パッケージの管理」に移動します。
次に、iTextSharpライブラリを検索して「インストール」をクリックします。
using iTextSharp.text.pdf;
using iTextSharp.text.html.simpleparser;
using iTextSharp.text.pdf;
using iTextSharp.text.html.simpleparser;
Imports iTextSharp.text.pdf
Imports iTextSharp.text.html.simpleparser
Install-Package IronPdf
Install-Package IronPdf
'INSTANT VB TODO TASK: The following line uses invalid syntax:
'Install-Package IronPdf
NuGet パッケージ マネージャーを使用してインストールする: 代わりに、ソリューション画面で NuGet パッケージ マネージャーを使用してインストールすることもできます。iTextSharp のステップと同様に実行しますが、今回は「インストール」をクリックする前に IronPDF を検索します。
using IronPdf;
using IronPdf;
Imports IronPdf
IronPDFは商業利用や開発以外での使用にはライセンスキーが必要であることを忘れないでください。
iTextSharpのセットアップが完了したら、プロジェクト内にitextsharp.xmlworkerパッケージがインストールされていることを確認する必要があります。その後、HTMLコンテンツからPDFを作成を開始できます。 しかし、特にCSSスタイルが含まれる場合は、より複雑なHTMLで課題に直面するでしょう。 iTextSharpは、IronPDFと比べて完璧なスタイリングを達成するために追加の労力が必要になる傾向があります。 iTextSharp は基本的な HTML/CSS2 のみを扱うことを忘れないでください(フレックスボックスなし、グリッドなし、CSS は限定的です)。
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using iTextSharp.text;
using iTextSharp.text.pdf;
using iTextSharp.tool.xml;
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
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>";
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))
{
XMLWorkerHelper.GetInstance().ParseXHtml(writer, pdfDoc, sr);
}
pdfDoc.Close();
writer.Close();
}
Console.WriteLine("PDF generation completed successfully.");
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using iTextSharp.text;
using iTextSharp.text.pdf;
using iTextSharp.tool.xml;
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
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>";
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))
{
XMLWorkerHelper.GetInstance().ParseXHtml(writer, pdfDoc, sr);
}
pdfDoc.Close();
writer.Close();
}
Console.WriteLine("PDF generation completed successfully.");
Imports System
Imports System.Collections.Generic
Imports System.IO
Imports System.Linq
Imports System.Text
Imports System.Threading.Tasks
Imports iTextSharp.text
Imports iTextSharp.text.pdf
Imports iTextSharp.tool.xml
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance)
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>"
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)
XMLWorkerHelper.GetInstance().ParseXHtml(writer, pdfDoc, sr)
End Using
pdfDoc.Close()
writer.Close()
End Using
Console.WriteLine("PDF generation completed successfully.")
出力PDFファイル
IronPDFは、PDF生成プロセスをシンプルにし、わずか数行のコードでHTMLコンテンツを新しいPDFドキュメントに簡単に変換できます。以下のコードサンプルでその例を示しています。 これは、スタイリングに使用されるCSSファイルを含む高度なHTMLドキュメントや、HTML文字列、CSS/JavaScriptを多用したウェブコンテンツを処理することができます。
インラインCSSを含む簡単な例を示します:
using IronPdf;
class Program
{
static void Main()
{
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>";
var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderHtmlAsPdf(htmlContent);
pdf.SaveAs("AdvancedStyledReport.pdf");
}
}
using IronPdf;
class Program
{
static void Main()
{
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>";
var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderHtmlAsPdf(htmlContent);
pdf.SaveAs("AdvancedStyledReport.pdf");
}
}
Imports IronPdf
Friend Class Program
Shared Sub Main()
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>"
Dim renderer = New ChromePdfRenderer()
Dim pdf = renderer.RenderHtmlAsPdf(htmlContent)
pdf.SaveAs("AdvancedStyledReport.pdf")
End Sub
End Class
出力PDFファイル
IronPDFを使用すると、上記のコード例のように正確なCSSスタイリングが施された洗練されたPDFファイルを期待できます。これにより、複雑なHTMLファイルや文字列などを扱う多くの開発者にとって頼りになる存在となっています。 IronPDFは、単純なHTMLからPDFへのドキュメント変換作業を超えて、高度なPDF操作およびPDFセキュリティ機能を備えています。 これにより、優れたオールインワンPDFライブラリになります。
iTextSharpとIronPDFを評価する際には、その機能だけでなく、競争環境も考慮することが重要です。 他の競合であるApryseやAspose.PDFも類似のHTMLからPDFへのソリューションを提供していますが、価格や機能面で独自のトレードオフがあります。
機能 IronPDF iTextSharp Apryse Aspose.PDF
使いやすさ 高い 中 高い 中
CSS サポート フル 部分的 フル フル
ライセンス 商業 オープンソース 商業 商用
サポート 優れた コミュニティ プレミアム プレミアム
価格 $749 から 無料/商用ライセンス 見積りベース 年間 $1,679 から
IronPDF は、最新のHTML5とCSS3の包括的なサポートにより際立っています。これは、今日のほとんどの開発者にとって重要です。 PDFドキュメントの操作における拡張サポート、PDFドキュメント作成のコントロール、変換プロセスの容易さなどにより、IronPDFは人気のPDFライブラリとなっています。
結論として、IronPDF と iTextSharp はどちらもC#でのHTMLからPDFへの変換に強力な機能を提供しますが、それぞれ異なるタイプの開発者を対象としています。 オープンソースのソリューションを探しており、強力なコミュニティサポートが必要な場合、iTextSharpが最適な選択肢かもしれません。しかし、使いやすさ、強力なCSSサポート、および商業的ソリューションを必要とする開発者にとっては、IronPDFがはるかにスムーズで機能豊富な体験を提供します。 請求書の自動生成、ブランド化されたPDFドキュメントの作成、またはウェブページ全体をPDFファイルに変換するツールをお探しの場合でも、IronPDFが対応します。
IronPDFのユーザーフレンドリーな機能を今日試してみてください–無料トライアルをダウンロードして、HTMLからPDFへの変換がいかに簡単かを実体験してください。