在C#中建立PDF的比較iTextSharp與IronPDF之間
1. 引言
在數位時代,PDF,也就是可攜式文件格式,已成為日常必需品,對於以可靠且一致的格式儲存和共享資訊至關重要。 無論是將資料屬性轉換成井然有序的PDF,或是製作專業的發票,開發者常使用像IronPDF和本地JSReport Studio這樣強大的C#客戶端程式庫,而不是Phantom PDF,用於伺服器開發。
IronPDF在將HTML轉換為PDF方面於.NET框架中提供了強大的性能,而JSReport SDK則提供動態報告解決方案,且著重於使用本地JSReport伺服器和配置文件的靈活性和定制化。 兩個程式庫都提供獨特的解決方案,滿足PDF生成和操作領域中開發者的不同需求。
2. 使用JSReport Server .NET
JSReport SDK .NET 是針對.NET應用特別優化的高級報告解決方案,特別是針對ASP.NET Core環境。 它的獨特之處在於能夠直接從HTML和JavaScript將視圖輸出轉變為多種格式,如PDF、Excel、DOCX和CSV。 這一功能是利用ASP.NET MVC引擎如Razor生成報告,一並使用報告伺服器開展的。
JSReport .NET提供了一套全面的預設本地擴充,包括排程、模板版本控制、子報告、使用者管理、匯入/匯出模板以及備份,增強其在各種商業場景中的適用性和多功能性。 它還支持廣泛的API,包括REST API、CLI和SDK,可以從幾乎任何地方進行報告渲染。
2.1 主要特點
2.1.1 ASP.NET Core整合
JSReport SDK提供了一個專為ASP.NET Core應用所設計的 jsreport.AspNetCore NuGet包。 這包括中介軟體過濾器,能夠將MVC視圖輸出轉換為所需格式,使用視圖作為HTML生成器以及JSReport伺服器作為輸出轉換器。
2.1.2 靈活設置
設置涉及使用如 jsreport.AspNetCore、jsreport.Local 和 jsreport.Binary的包。 這些輔助類促進了連接本地JSReport實例或通過jsreport.Client連接遠程實例。
2.1.3 輸出轉換
開發者可以輕鬆指定JSReport的配方進行輸出轉換。 例如,使用 MiddlewareFilter 和 ChromePdf 配方,一個ASP.NET過濾器可以捕獲視圖的渲染結果並轉換成PDF格式。 這一功能對基於ASP.NET的應用特別有幫助。
2.1.4 遠程實例相容性
JSReport .NET可以無縫整合遠程的JSReport實例。 這在JSReport運行於獨立容器的有序Docker環境中特別有利。 這樣的整合有助於使用如Docker-compose等工具進行JSReport和.NET Core應用的編排。
2.1.5 高級響應處理
OnAfterRender 鉤子允許對響應頭和其他屬性進行操作。 該鉤子還可以用來將輸出儲存到文件中,提供了處理報告生成過程中響應的靈活性。
2.1.6 自定義標題
JSReport .NET允許通過部分視圖指定自定義PDF標題。 這些標題可以在運行時連同主PDF內容一起渲染,為報告生成提供了額外的自定義選項。
2.1.7 無需MVC視圖渲染
該框架支持直接從原始HTML渲染報告,而不僅僅是MVC視圖。 這一功能使報告生成過程更加靈活,使開發者能夠直接渲染HTML內容。
3. IronPDF
IronPDF是一個針對.NET應用程式實現PDF處理的有用程式庫,著力於簡化PDF的操作。 它的一個主要功能是將HTML轉換成PDF,這非常適合從網頁生成報告或發票。 它在伺服器端和客戶端應用上均效率高,非常適合商業項目和個人使用。
IronPDF能很好地整合到多種.NET環境中,如ASP.NET、MVC、Windows Forms和WPF,並能與.NET Core和 Framework順暢協作。 它還支持Azure及其他雲服務,這對於基於雲的應用開發是一大優勢。
3.1 IronPDF的主要特點
3.1.1 HTML轉PDF
IronPDF非常擅長將HTML轉換成PDF文件。 它能輕鬆處理HTML、CSS、JavaScript和圖片,保證您的網頁內容在最終的PDF中看起來完美無瑕。 該轉換保留了原始HTML的佈局和樣式。
3.1.2 ASP.NET整合
與ASP.NET的整合無縫,允許將ASPX頁面轉換為PDF,而不需大量編碼。 這對從現有網頁應用建立PDF特別有用。
3.1.3 編輯與操作
IronPDF允許您編輯現有的PDF文件,例如新增文字、圖片和頁面或合併多個PDF。 編輯功能使用者友好,因此不需要PDF專業知識即可使用。 您還可以為您的PDF新增註釋、附件、大綱和書籤。
3.1.4 表單填充與提取
IronPDF支持填寫和提取PDF表單中的資料,這對於處理表單的應用至關重要。 IronPDF使管理表單資料的整個過程更加順暢,並且能夠處理不同型別的PDF表單,提高其靈活性。
3.1.5 安全功能
IronPDF包括如密碼保護和設定PDF文件權限這樣的安全功能,這對於保護敏感資訊至關重要。 它包括加密和解密功能,為您的PDF新增了另一層安全性。
3.1.6 可自定義渲染
您可以對PDF的渲染方式有廣泛控制,如設置自定義頁眉和頁腳,調整頁面邊距,以及選擇特定的HTML部分進行轉換。 這種自定義確保您的PDF完全符合您的期望。
3.1.7 高級PDF功能
IronPDF支持PDF/A合規和數位簽名,以及OCR功能,因此它可以將掃描文件和圖片轉換為可搜索、可編輯的PDF。 這些功能對於更為複雜的專案是理想的選擇。
3.1.8 簡易部署
設置IronPDF非常簡單; 不需要額外的安裝或依賴。 它很輕量級以確保不會對您的應用程式性能產生負面影響。 此外,它會定期更新以符合最新的.NET技術,提供一個仍然相關的PDF解決方案。
4. 建立.NET專案
4.1 開始一個新專案
打開Visual Studio並點擊"建立一個新專案"按鈕以啟動新專案。

然後,選擇'控制台應用','.NET Core應用'或其他適合您需求的選項。

4.2 設置專案
您需要為您的專案命名。 在專案名稱的文字框中輸入您想要的名稱。 選擇您想要保存專案的路徑位置。 輸入這些詳細資料後,點擊'建立'按鈕繼續。

4.3 選擇.NET Framework
下一步是選擇專案所需的.NET framework。 這一選擇取決於您的專案要求及相容性。 之後,點擊'建立'按鈕。

5. 安裝IronPDF程式庫
5.1 使用NuGet封裝管理器
若要使用Visual Studio的NuGet封裝管理器安裝IronPDF,請遵循以下步驟:
- 在Visual Studio中開啟專案。
-
點擊"工具"選單,選擇"NuGet封裝管理器",然後選擇"為解決方案管理NuGet封裝"。

- 在NuGet封裝管理器中,點擊"瀏覽"標籤。
- 搜尋"IronPDF"。
-
找到IronPDF包後,選擇並點擊"安裝"。

- 按照提示完成安裝。
5.2 使用Visual Studio命令行
如果您喜歡使用命令行,您可以按照以下步驟在Visual Studio中安裝IronPDF:
- 打開Visual Studio。
- 移動至"工具"選單,懸停於"NuGet封包管理器",然後從側面選單選擇"Packager管理器控制台"。
-
在控制台中輸入以下命令:
Install-Package IronPdf
-
按下Enter執行命令並等待安裝完成。

5.3 從NuGet網頁直接下載
IronPDF也可以直接從NuGet網站下載:
- 存取NuGet官方網站。
-
使用搜索欄尋找IronPDF包。

- 在IronPDF封裝頁面,您將看到直接下載封裝選項。
-
下載.nupkg文件並手動新增到您的專案中。

6. 安裝JSReport
6.1 在Visual Studio中使用NuGet封包管理器
要使用Visual Studio的NuGet封包管理器運行JSReport,請轉到'工具'選單並選擇'管理NuGet封裝'。 這將打開NuGet封裝管理器介面。 在NuGet封包管理器中,您可以根據您的專案需求搜尋 jsreport.Local 或 jsreport.Binary。

這些是將JSReport整合到.NET應用中的主要包。 找到合適的包後,點擊'安裝'將其新增到專案中。 此過程將自動下載並引用專案中的包,使其可以隨時使用。
6.2 使用NuGet封裝管理器控制台
或者,您可以使用Visual Studio中的NuGet封包管理器控制台安裝JSReport。 從'工具'選單中選擇'NuGet封包管理器',然後選擇'封包管理器控制台'以打開NuGet封包管理器控制台。

在控制台中,您需要運行特定命令來安裝JSReport封裝。 如果您想要安裝 jsreport.Local包,您可以使用命令 Install-Package jsreport.Local。 對於 jsreport.Binary包,則使用命令 Install-Package jsreport.Binary。 在封包管理器控制台中執行這些命令將下載並將相應JSReport封裝新增到專案中。

7. 比較IronPDF和JSReport的HTML轉PDF功能
7.1 IronPDF的HTML轉PDF
IronPDF是HTML轉PDF的頂級庫,以使用簡單和高性能著稱。 它支持高階功能,如CSS渲染、JavaScript執行和自定義頁眉頁腳,增強其從HTML來源生成優質PDF的能力。 IronPDF提供三種將HTML轉換為PDF的方法:
- HTML字串到PDF
- HTML文件到PDF
- URL到PDF
讓我們單獨討論這些方法。
7.1.1 HTML字串到PDF
此功能允許您直接從字串轉換HTML內容,對於在應用程式內動態生成或修改的HTML內容特別有用。 通過將HTML字串傳遞給IronPDF,它會被渲染成一個PDF。
using IronPdf;
// Initialize the ChromePdfRenderer
var renderer = new ChromePdfRenderer();
// License key setup
IronPdf.License.LicenseKey = "Your-License-Key";
// HTML string to be converted
string htmlString = @"
<html>
<head>
<title>Example HTML</title>
</head>
<body>
<h1>Hello, World!</h1>
<p>This is an HTML string converted to PDF using IronPDF.</p>
</body>
</html>";
// Convert HTML string to PDF
var pdfDocument = renderer.RenderHtmlAsPdf(htmlString);
// Save the rendered PDF document
pdfDocument.SaveAs("HtmlStringToPdf.pdf");
using IronPdf;
// Initialize the ChromePdfRenderer
var renderer = new ChromePdfRenderer();
// License key setup
IronPdf.License.LicenseKey = "Your-License-Key";
// HTML string to be converted
string htmlString = @"
<html>
<head>
<title>Example HTML</title>
</head>
<body>
<h1>Hello, World!</h1>
<p>This is an HTML string converted to PDF using IronPDF.</p>
</body>
</html>";
// Convert HTML string to PDF
var pdfDocument = renderer.RenderHtmlAsPdf(htmlString);
// Save the rendered PDF document
pdfDocument.SaveAs("HtmlStringToPdf.pdf");
Imports IronPdf
' Initialize the ChromePdfRenderer
Private renderer = New ChromePdfRenderer()
' License key setup
IronPdf.License.LicenseKey = "Your-License-Key"
' HTML string to be converted
Dim htmlString As String = "
<html>
<head>
<title>Example HTML</title>
</head>
<body>
<h1>Hello, World!</h1>
<p>This is an HTML string converted to PDF using IronPDF.</p>
</body>
</html>"
' Convert HTML string to PDF
Dim pdfDocument = renderer.RenderHtmlAsPdf(htmlString)
' Save the rendered PDF document
pdfDocument.SaveAs("HtmlStringToPdf.pdf")
7.1.2 HTML文件到PDF
此方法將現有的HTML文件轉換成PDF,非常適合需要作為PDF進行展示或分發的靜態HTML文件。 提供HTML文件的路徑,IronPDF會處理轉換。
using IronPdf;
// Initialize the ChromePdfRenderer
var renderer = new ChromePdfRenderer();
// License key setup
IronPdf.License.LicenseKey = "Your-License-Key";
// Convert HTML file to PDF
var pdfDocument = renderer.RenderHtmlFileAsPdf("invoice.html");
// Save the PDF document
pdfDocument.SaveAs("Invoice.pdf");
using IronPdf;
// Initialize the ChromePdfRenderer
var renderer = new ChromePdfRenderer();
// License key setup
IronPdf.License.LicenseKey = "Your-License-Key";
// Convert HTML file to PDF
var pdfDocument = renderer.RenderHtmlFileAsPdf("invoice.html");
// Save the PDF document
pdfDocument.SaveAs("Invoice.pdf");
Imports IronPdf
' Initialize the ChromePdfRenderer
Private renderer = New ChromePdfRenderer()
' License key setup
IronPdf.License.LicenseKey = "Your-License-Key"
' Convert HTML file to PDF
Dim pdfDocument = renderer.RenderHtmlFileAsPdf("invoice.html")
' Save the PDF document
pdfDocument.SaveAs("Invoice.pdf")
7.1.3 URL到PDF
此功能通過URL將整個網頁轉換成PDF,方便捕捉網頁當前狀態,包括樣式、圖片和其他資源。 IronPDF將從提供的URL載入網頁並將其轉換為PDF文件,盡可能精確地重現佈局和內容。
using IronPdf;
// Initialize the ChromePdfRenderer
var renderer = new ChromePdfRenderer();
// License key setup
IronPdf.License.LicenseKey = "Your-License-Key";
// Set the Paper Size
renderer.RenderingOptions.PaperSize = IronPdf.Rendering.PdfPaperSize.A2;
// Convert webpage to PDF
var pdfDocument = renderer.RenderUrlAsPdf("https://dotnet.microsoft.com/");
// Save the PDF document
pdfDocument.SaveAs("UrlToPdf.pdf");
using IronPdf;
// Initialize the ChromePdfRenderer
var renderer = new ChromePdfRenderer();
// License key setup
IronPdf.License.LicenseKey = "Your-License-Key";
// Set the Paper Size
renderer.RenderingOptions.PaperSize = IronPdf.Rendering.PdfPaperSize.A2;
// Convert webpage to PDF
var pdfDocument = renderer.RenderUrlAsPdf("https://dotnet.microsoft.com/");
// Save the PDF document
pdfDocument.SaveAs("UrlToPdf.pdf");
Imports IronPdf
' Initialize the ChromePdfRenderer
Private renderer = New ChromePdfRenderer()
' License key setup
IronPdf.License.LicenseKey = "Your-License-Key"
' Set the Paper Size
renderer.RenderingOptions.PaperSize = IronPdf.Rendering.PdfPaperSize.A2
' Convert webpage to PDF
Dim pdfDocument = renderer.RenderUrlAsPdf("https://dotnet.microsoft.com/")
' Save the PDF document
pdfDocument.SaveAs("UrlToPdf.pdf")
7.2 JSReport C# HTML轉換為PDF
在JSReport中將HTML轉換為PDF涉及多個步驟,通常包括設置JSReport伺服器或使用其在線API。 在C#中的典型實現可能是這樣的:
using JsReport.AspNetCore;
using JsReport.Types;
using System.Threading.Tasks;
public async Task<IActionResult> GeneratePdf()
{
var report = new LocalReporting()
.UseBinary(JsReportBinary.GetBinary())
.AsUtility()
.Create();
var reportResult = await report.RenderAsync(new RenderRequest()
{
Template = new Template()
{
Content = "<html><body><h1>Example HTML</h1><p>This is converted to PDF using JSReport.</p></body></html>",
Engine = Engine.None,
Recipe = Recipe.ChromePdf
},
Options = new RenderOptions()
{
Debug = new DebugOptions() { Preview = true }
}
});
var stream = new MemoryStream();
reportResult.Content.CopyTo(stream);
stream.Position = 0;
return File(stream, "application/pdf", "Report.pdf");
}
using JsReport.AspNetCore;
using JsReport.Types;
using System.Threading.Tasks;
public async Task<IActionResult> GeneratePdf()
{
var report = new LocalReporting()
.UseBinary(JsReportBinary.GetBinary())
.AsUtility()
.Create();
var reportResult = await report.RenderAsync(new RenderRequest()
{
Template = new Template()
{
Content = "<html><body><h1>Example HTML</h1><p>This is converted to PDF using JSReport.</p></body></html>",
Engine = Engine.None,
Recipe = Recipe.ChromePdf
},
Options = new RenderOptions()
{
Debug = new DebugOptions() { Preview = true }
}
});
var stream = new MemoryStream();
reportResult.Content.CopyTo(stream);
stream.Position = 0;
return File(stream, "application/pdf", "Report.pdf");
}
Imports JsReport.AspNetCore
Imports JsReport.Types
Imports System.Threading.Tasks
Public Async Function GeneratePdf() As Task(Of IActionResult)
Dim report = (New LocalReporting()).UseBinary(JsReportBinary.GetBinary()).AsUtility().Create()
Dim reportResult = Await report.RenderAsync(New RenderRequest() With {
.Template = New Template() With {
.Content = "<html><body><h1>Example HTML</h1><p>This is converted to PDF using JSReport.</p></body></html>",
.Engine = Engine.None,
.Recipe = Recipe.ChromePdf
},
.Options = New RenderOptions() With {
.Debug = New DebugOptions() With {.Preview = True}
}
})
Dim stream = New MemoryStream()
reportResult.Content.CopyTo(stream)
stream.Position = 0
Return File(stream, "application/pdf", "Report.pdf")
End Function
欲查看更多JSReport .NET範例,請存取以下連結。
7.3. Bootstrap和現代CSS框架渲染
現代使用CSS框架如Bootstrap構建的網頁應用需要能準確保存框架佈局和響應設計元素的PDF生成工具。
IronPDF:完整的 Bootstrap 和框架支持
IronPDF的Chromium渲染引擎為所有現代CSS框架提供了全面支援:
- Bootstrap 5: 完整的 flexbox 和 CSS Grid,帶有所有響應式工具
- Bootstrap 4:完整的卡片系統、導航、表單元件
- Tailwind CSS: 所有實用類和響應式修飾符
- Foundation: 全面支持網格和組件系統
- 現代 CSS3: Flexbox、Grid、自定義屬性、動畫、變形
已通過實際範例驗證:Bootstrap 主頁和Bootstrap 範本以像素完美的準確度轉換。
程式碼範例:使用Bootstrap的功能比較表
using IronPdf;
var renderer = new ChromePdfRenderer();
string bootstrapComparison = @"
<!DOCTYPE html>
<html>
<head>
<link href='https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css' rel='stylesheet'>
</head>
<body>
<div class='container my-5'>
<h1 class='text-center mb-5'>Feature Comparison</h1>
<div class='table-responsive'>
<table class='table table-bordered table-hover'>
<thead class='table-primary'>
<tr>
<th style='width: 30%'>Feature</th>
<th style='width: 35%' class='text-center'>IronPDF</th>
<th style='width: 35%' class='text-center'>Alternative</th>
</tr>
</thead>
<tbody>
<tr>
<td><strong>HTML5 Support</strong></td>
<td class='text-center'>
<span class='badge bg-success fs-6'>Full Support</span>
<p class='text-muted small mb-0 mt-2'>Modern web standards</p>
</td>
<td class='text-center'>
<span class='badge bg-warning fs-6'>Partial</span>
<p class='text-muted small mb-0 mt-2'>Basic HTML only</p>
</td>
</tr>
<tr>
<td><strong>CSS3 & Flexbox</strong></td>
<td class='text-center'>
<span class='badge bg-success fs-6'>Full Support</span>
<p class='text-muted small mb-0 mt-2'>Chromium engine</p>
</td>
<td class='text-center'>
<span class='badge bg-danger fs-6'>Limited</span>
<p class='text-muted small mb-0 mt-2'>No flexbox/grid</p>
</td>
</tr>
<tr>
<td><strong>JavaScript Execution</strong></td>
<td class='text-center'>
<span class='badge bg-success fs-6'>Full Support</span>
<p class='text-muted small mb-0 mt-2'>V8 engine</p>
</td>
<td class='text-center'>
<span class='badge bg-warning fs-6'>Partial</span>
<p class='text-muted small mb-0 mt-2'>Limited execution</p>
</td>
</tr>
<tr>
<td><strong>Bootstrap 5</strong></td>
<td class='text-center'>
<span class='badge bg-success fs-6'>Full Support</span>
<p class='text-muted small mb-0 mt-2'>All components</p>
</td>
<td class='text-center'>
<span class='badge bg-danger fs-6'>No Support</span>
<p class='text-muted small mb-0 mt-2'>Bootstrap 3 only</p>
</td>
</tr>
<tr class='table-secondary'>
<td><strong>Deployment</strong></td>
<td class='text-center'>
<div class='d-flex justify-content-center gap-2 flex-wrap'>
<span class='badge bg-primary'>On-Premises</span>
<span class='badge bg-primary'>Cloud</span>
<span class='badge bg-primary'>Offline</span>
</div>
</td>
<td class='text-center'>
<div class='d-flex justify-content-center gap-2 flex-wrap'>
<span class='badge bg-secondary'>Server Only</span>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<div class='alert alert-info mt-4 d-flex align-items-start'>
<svg class='bi flex-shrink-0 me-2 mt-1' width='20' height='20'></svg>
<div>
<strong>Note:</strong> IronPDF's Chromium engine ensures that modern web applications convert to PDF with browser-accurate fidelity, preserving all CSS frameworks and responsive designs.
</div>
</div>
</div>
</body>
</html>";
var pdf = renderer.RenderHtmlAsPdf(bootstrapComparison);
pdf.SaveAs("feature-comparison.pdf");
using IronPdf;
var renderer = new ChromePdfRenderer();
string bootstrapComparison = @"
<!DOCTYPE html>
<html>
<head>
<link href='https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css' rel='stylesheet'>
</head>
<body>
<div class='container my-5'>
<h1 class='text-center mb-5'>Feature Comparison</h1>
<div class='table-responsive'>
<table class='table table-bordered table-hover'>
<thead class='table-primary'>
<tr>
<th style='width: 30%'>Feature</th>
<th style='width: 35%' class='text-center'>IronPDF</th>
<th style='width: 35%' class='text-center'>Alternative</th>
</tr>
</thead>
<tbody>
<tr>
<td><strong>HTML5 Support</strong></td>
<td class='text-center'>
<span class='badge bg-success fs-6'>Full Support</span>
<p class='text-muted small mb-0 mt-2'>Modern web standards</p>
</td>
<td class='text-center'>
<span class='badge bg-warning fs-6'>Partial</span>
<p class='text-muted small mb-0 mt-2'>Basic HTML only</p>
</td>
</tr>
<tr>
<td><strong>CSS3 & Flexbox</strong></td>
<td class='text-center'>
<span class='badge bg-success fs-6'>Full Support</span>
<p class='text-muted small mb-0 mt-2'>Chromium engine</p>
</td>
<td class='text-center'>
<span class='badge bg-danger fs-6'>Limited</span>
<p class='text-muted small mb-0 mt-2'>No flexbox/grid</p>
</td>
</tr>
<tr>
<td><strong>JavaScript Execution</strong></td>
<td class='text-center'>
<span class='badge bg-success fs-6'>Full Support</span>
<p class='text-muted small mb-0 mt-2'>V8 engine</p>
</td>
<td class='text-center'>
<span class='badge bg-warning fs-6'>Partial</span>
<p class='text-muted small mb-0 mt-2'>Limited execution</p>
</td>
</tr>
<tr>
<td><strong>Bootstrap 5</strong></td>
<td class='text-center'>
<span class='badge bg-success fs-6'>Full Support</span>
<p class='text-muted small mb-0 mt-2'>All components</p>
</td>
<td class='text-center'>
<span class='badge bg-danger fs-6'>No Support</span>
<p class='text-muted small mb-0 mt-2'>Bootstrap 3 only</p>
</td>
</tr>
<tr class='table-secondary'>
<td><strong>Deployment</strong></td>
<td class='text-center'>
<div class='d-flex justify-content-center gap-2 flex-wrap'>
<span class='badge bg-primary'>On-Premises</span>
<span class='badge bg-primary'>Cloud</span>
<span class='badge bg-primary'>Offline</span>
</div>
</td>
<td class='text-center'>
<div class='d-flex justify-content-center gap-2 flex-wrap'>
<span class='badge bg-secondary'>Server Only</span>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<div class='alert alert-info mt-4 d-flex align-items-start'>
<svg class='bi flex-shrink-0 me-2 mt-1' width='20' height='20'></svg>
<div>
<strong>Note:</strong> IronPDF's Chromium engine ensures that modern web applications convert to PDF with browser-accurate fidelity, preserving all CSS frameworks and responsive designs.
</div>
</div>
</div>
</body>
</html>";
var pdf = renderer.RenderHtmlAsPdf(bootstrapComparison);
pdf.SaveAs("feature-comparison.pdf");
Imports IronPdf
Dim renderer As New ChromePdfRenderer()
Dim bootstrapComparison As String = "
<!DOCTYPE html>
<html>
<head>
<link href='https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css' rel='stylesheet'>
</head>
<body>
<div class='container my-5'>
<h1 class='text-center mb-5'>Feature Comparison</h1>
<div class='table-responsive'>
<table class='table table-bordered table-hover'>
<thead class='table-primary'>
<tr>
<th style='width: 30%'>Feature</th>
<th style='width: 35%' class='text-center'>IronPDF</th>
<th style='width: 35%' class='text-center'>Alternative</th>
</tr>
</thead>
<tbody>
<tr>
<td><strong>HTML5 Support</strong></td>
<td class='text-center'>
<span class='badge bg-success fs-6'>Full Support</span>
<p class='text-muted small mb-0 mt-2'>Modern web standards</p>
</td>
<td class='text-center'>
<span class='badge bg-warning fs-6'>Partial</span>
<p class='text-muted small mb-0 mt-2'>Basic HTML only</p>
</td>
</tr>
<tr>
<td><strong>CSS3 & Flexbox</strong></td>
<td class='text-center'>
<span class='badge bg-success fs-6'>Full Support</span>
<p class='text-muted small mb-0 mt-2'>Chromium engine</p>
</td>
<td class='text-center'>
<span class='badge bg-danger fs-6'>Limited</span>
<p class='text-muted small mb-0 mt-2'>No flexbox/grid</p>
</td>
</tr>
<tr>
<td><strong>JavaScript Execution</strong></td>
<td class='text-center'>
<span class='badge bg-success fs-6'>Full Support</span>
<p class='text-muted small mb-0 mt-2'>V8 engine</p>
</td>
<td class='text-center'>
<span class='badge bg-warning fs-6'>Partial</span>
<p class='text-muted small mb-0 mt-2'>Limited execution</p>
</td>
</tr>
<tr>
<td><strong>Bootstrap 5</strong></td>
<td class='text-center'>
<span class='badge bg-success fs-6'>Full Support</span>
<p class='text-muted small mb-0 mt-2'>All components</p>
</td>
<td class='text-center'>
<span class='badge bg-danger fs-6'>No Support</span>
<p class='text-muted small mb-0 mt-2'>Bootstrap 3 only</p>
</td>
</tr>
<tr class='table-secondary'>
<td><strong>Deployment</strong></td>
<td class='text-center'>
<div class='d-flex justify-content-center gap-2 flex-wrap'>
<span class='badge bg-primary'>On-Premises</span>
<span class='badge bg-primary'>Cloud</span>
<span class='badge bg-primary'>Offline</span>
</div>
</td>
<td class='text-center'>
<div class='d-flex justify-content-center gap-2 flex-wrap'>
<span class='badge bg-secondary'>Server Only</span>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<div class='alert alert-info mt-4 d-flex align-items-start'>
<svg class='bi flex-shrink-0 me-2 mt-1' width='20' height='20'></svg>
<div>
<strong>Note:</strong> IronPDF's Chromium engine ensures that modern web applications convert to PDF with browser-accurate fidelity, preserving all CSS frameworks and responsive designs.
</div>
</div>
</div>
</body>
</html>"
Dim pdf = renderer.RenderHtmlAsPdf(bootstrapComparison)
pdf.SaveAs("feature-comparison.pdf")
輸出:一個專業的功能比較表,具有Bootstrap的表格樣式、徽章、響應佈局和警告元件——所有這些都能精確地在PDF中渲染。
JSReport .NET:基於模板的Bootstrap支持有限
JSReport使用基於模板的方法,其渲染引擎根據所選配方而異:
- Chrome PDF配方:使用Puppeteer/Headless Chrome,Bootstrap支持良好
- Phantom JS配方:舊WebKit引擎,對現代CSS支持有限
- wkhtmltopdf配方:Qt WebKit引擎(過時,無支持flexbox/grid)
- 模板複雜性:需要學習JSReport的模板語法
- 伺服器依賴:需要安裝和管理JSReport伺服器
JSReport和Bootstrap的主要考慮因素:
- 配方選擇:Bootstrap支持因配方選擇而異大
- Chrome PDF配方:最佳選擇,但增加了複雜性和依賴性
- 模板學習曲線:必須學習Handlebars/JSRender模板語法
- 伺服器管理:需要維護JSReport伺服器實例
- 工作流程複雜性:多步驟的模板→資料→渲染過程
對開發的影響:雖然JSReport的Chrome PDF配方對Bootstrap有很好的處理能力,但整體複雜性較高:
- 基於模板的工作流與直接HTML轉換
- 伺服器基礎設施需求與進程內程式庫
- 模板語法的學習曲線與標準HTML
- 配方配置的複雜性與簡單API
對於需要簡單的HTML到PDF轉換並支持Bootstrap的應用,IronPDF的直接方法提供了更簡單的整合和更少的運行問題。
對於Bootstrap框架的最佳實踐,請參見Bootstrap & Flexbox CSS指南。
8. 靈活性和高級功能
8.1 IronPDF的高級功能及自定義
IronPDF以其高級功能和卓越的自定義能力而聞名,滿足各種PDF操作需求。 主要高級功能包括:
PDF/A 合規
IronPDF支持PDF/A格式,這對於長期歸檔和行業標準合規至關重要。 這一合規特別對於法律、金融和政府部門尤為重要,因為這些領域對文件的長期完整性要求極高。
using IronPdf;
// Create a PdfDocument object or open any PDF File
PdfDocument pdf = PdfDocument.FromFile("wikipedia.pdf");
// Use the SaveAsPdfA method to save to file
pdf.SaveAsPdfA("pdf-a3-wikipedia.pdf", PdfAVersions.PdfA3);
using IronPdf;
// Create a PdfDocument object or open any PDF File
PdfDocument pdf = PdfDocument.FromFile("wikipedia.pdf");
// Use the SaveAsPdfA method to save to file
pdf.SaveAsPdfA("pdf-a3-wikipedia.pdf", PdfAVersions.PdfA3);
Imports IronPdf
' Create a PdfDocument object or open any PDF File
Private pdf As PdfDocument = PdfDocument.FromFile("wikipedia.pdf")
' Use the SaveAsPdfA method to save to file
pdf.SaveAsPdfA("pdf-a3-wikipedia.pdf", PdfAVersions.PdfA3)
編輯、合併和拆分PDF
IronPDF允許編輯現有的PDF、將多個PDF合併為一個,以及將PDF拆分為單獨的文件。 這個功能在需要分解大文件以方便分發或在需要將不同文件的多個部分合併時特別有用。
安全功能
IronPDF包括強大的安全功能,如密碼保護、加密和設置使用者權限。 IronPDF支持PDF文件加密,增添了一層額外的安全性,防止內容被篡改或複製。
using IronPdf;
// Open a PDF File
var pdfDoc = PdfDocument.FromFile("invoice.pdf");
// Make a PDF read-only and disallow copy & paste and printing
pdfDoc.SecuritySettings.RemovePasswordsAndEncryption();
pdfDoc.SecuritySettings.AllowUserAnnotations = false;
pdfDoc.SecuritySettings.AllowUserCopyPasteContent = false;
pdfDoc.SecuritySettings.AllowUserPrinting = IronPdf.Security.PdfPrintSecurity.FullPrintRights;
pdfDoc.SecuritySettings.MakePdfDocumentReadOnly("secret-key");
pdfDoc.SecuritySettings.AllowUserFormData = false;
// Change or set the document encryption password
pdfDoc.SecuritySettings.OwnerPassword = "passForOpen"; // password to edit the pdf
pdfDoc.SecuritySettings.UserPassword = "onlyForShare"; // password to open the pdf
// Save the protected PDF
pdfDoc.SaveAs("InvoiceProtected.pdf");
using IronPdf;
// Open a PDF File
var pdfDoc = PdfDocument.FromFile("invoice.pdf");
// Make a PDF read-only and disallow copy & paste and printing
pdfDoc.SecuritySettings.RemovePasswordsAndEncryption();
pdfDoc.SecuritySettings.AllowUserAnnotations = false;
pdfDoc.SecuritySettings.AllowUserCopyPasteContent = false;
pdfDoc.SecuritySettings.AllowUserPrinting = IronPdf.Security.PdfPrintSecurity.FullPrintRights;
pdfDoc.SecuritySettings.MakePdfDocumentReadOnly("secret-key");
pdfDoc.SecuritySettings.AllowUserFormData = false;
// Change or set the document encryption password
pdfDoc.SecuritySettings.OwnerPassword = "passForOpen"; // password to edit the pdf
pdfDoc.SecuritySettings.UserPassword = "onlyForShare"; // password to open the pdf
// Save the protected PDF
pdfDoc.SaveAs("InvoiceProtected.pdf");
Imports IronPdf
' Open a PDF File
Private pdfDoc = PdfDocument.FromFile("invoice.pdf")
' Make a PDF read-only and disallow copy & paste and printing
pdfDoc.SecuritySettings.RemovePasswordsAndEncryption()
pdfDoc.SecuritySettings.AllowUserAnnotations = False
pdfDoc.SecuritySettings.AllowUserCopyPasteContent = False
pdfDoc.SecuritySettings.AllowUserPrinting = IronPdf.Security.PdfPrintSecurity.FullPrintRights
pdfDoc.SecuritySettings.MakePdfDocumentReadOnly("secret-key")
pdfDoc.SecuritySettings.AllowUserFormData = False
' Change or set the document encryption password
pdfDoc.SecuritySettings.OwnerPassword = "passForOpen" ' password to edit the pdf
pdfDoc.SecuritySettings.UserPassword = "onlyForShare" ' password to open the pdf
' Save the protected PDF
pdfDoc.SaveAs("InvoiceProtected.pdf")
頁眉和頁腳控制
開發者可以輕鬆地將自定義頁眉和頁腳新增到PDF文件中,這對於專業報告、發票和其他企業文件至關重要。 這包括能夠新增頁碼、日期和自定義文字。
PDF到影像轉換
IronPDF允許將PDF頁面轉換為圖片。 這一功能特別適合於將PDF內容作為圖片顯示於Web應用或用於生成縮略圖的場景。
using IronPdf;
using IronSoftware.Drawing;
// Load the PDF document
var pdf = PdfDocument.FromFile("Example.pdf");
// Extract all pages to a folder as PNG image files
pdf.RasterizeToImageFiles(@"C:\image\folder\*.png");
// Extract specific dimensions or page ranges
pdf.RasterizeToImageFiles(@"C:\image\folder\example_pdf_image_*.jpg", 100, 80);
// Extract all pages as AnyBitmap objects
AnyBitmap [] pdfBitmaps = pdf.ToBitmap();
using IronPdf;
using IronSoftware.Drawing;
// Load the PDF document
var pdf = PdfDocument.FromFile("Example.pdf");
// Extract all pages to a folder as PNG image files
pdf.RasterizeToImageFiles(@"C:\image\folder\*.png");
// Extract specific dimensions or page ranges
pdf.RasterizeToImageFiles(@"C:\image\folder\example_pdf_image_*.jpg", 100, 80);
// Extract all pages as AnyBitmap objects
AnyBitmap [] pdfBitmaps = pdf.ToBitmap();
Imports IronPdf
Imports IronSoftware.Drawing
' Load the PDF document
Private pdf = PdfDocument.FromFile("Example.pdf")
' Extract all pages to a folder as PNG image files
pdf.RasterizeToImageFiles("C:\image\folder\*.png")
' Extract specific dimensions or page ranges
pdf.RasterizeToImageFiles("C:\image\folder\example_pdf_image_*.jpg", 100, 80)
' Extract all pages as AnyBitmap objects
Dim pdfBitmaps() As AnyBitmap = pdf.ToBitmap()
8.2 JSReport .NET高級功能及可擴充性
JSReport .NET因其高級功能和可擴充性而聞名,是生成報告的多功能工具。 其主要功能包括:
動態報告生成
它支持各種模板引擎,包括Handlebars和EJS,有助於精細和靈活的報告設計。 這種多引擎相容性允許滿足不同需求和報告建立的複雜性,適合於多樣化的設計可能性。
var report = new LocalReporting()
.UseBinary(JsReportBinary.GetBinary())
.RunInDirectory(Path.Combine(Directory.GetCurrentDirectory(), "jsreport"))
.KillRunningJsReportProcesses()
.Configure(cfg => cfg.AllowLocalFilesAccess().FileSystemStore().BaseUrlAsWorkingDirectory())
.AsUtility()
.Create();
var reportResult = await report.RenderAsync(new RenderRequest()
{
Template = new Template()
{
Content = "{{{message}}}",
Engine = Engine.Handlebars,
Recipe = Recipe.ChromePdf
},
Data = new
{
message = "PDF Generation with JSReport .NET"
}
});
var report = new LocalReporting()
.UseBinary(JsReportBinary.GetBinary())
.RunInDirectory(Path.Combine(Directory.GetCurrentDirectory(), "jsreport"))
.KillRunningJsReportProcesses()
.Configure(cfg => cfg.AllowLocalFilesAccess().FileSystemStore().BaseUrlAsWorkingDirectory())
.AsUtility()
.Create();
var reportResult = await report.RenderAsync(new RenderRequest()
{
Template = new Template()
{
Content = "{{{message}}}",
Engine = Engine.Handlebars,
Recipe = Recipe.ChromePdf
},
Data = new
{
message = "PDF Generation with JSReport .NET"
}
});
Dim report = (New LocalReporting()).UseBinary(JsReportBinary.GetBinary()).RunInDirectory(Path.Combine(Directory.GetCurrentDirectory(), "jsreport")).KillRunningJsReportProcesses().Configure(Function(cfg) cfg.AllowLocalFilesAccess().FileSystemStore().BaseUrlAsWorkingDirectory()).AsUtility().Create()
Dim reportResult = Await report.RenderAsync(New RenderRequest() With {
.Template = New Template() With {
.Content = "{{{message}}}",
.Engine = Engine.Handlebars,
.Recipe = Recipe.ChromePdf
},
.Data = New With {Key .message = "PDF Generation with JSReport .NET"}
})
模板引擎
JSReport .NET具有排程和自動化功能,用於生成報告,非常適合於需要定期報告需求,如逐日或逐月的總結。 這一功能確保了即時交付報告,並可以與業務工作流相整合,進行事件觸發的報告。
使用自定義腳本的可擴充性
JSReport C#允許通過自定義腳本擴充其功能,加強了如自定義資料處理或專業格式化等功能。 這種可擴充性對於建立符合特定業務邏輯和資料操作需求的報告至關重要。
9. 支援
9.1 IronPDF文件質量及可用性
IronPDF的文件齊全且使用者友好,滿足初學者及有經驗的開發者。 它包含詳細指引、API參考和大量程式碼範例,讓開發者更輕鬆地了解和實施此程式庫的多語言功能,比如C#和Node。
文件結構完備且定期更新,反映最新功能與最佳實踐。 此外,IronPDF網站還提供快速開始指南和常見問題解答,對於首次接觸PDF操作的.NET環境新手特別有幫助。
IronPDF還有一個線上遊樂場,您可以在線嘗試IronPDF功能而無需下載其程式碼。 通過以下連結進行探索。
9.1.1 支援方案
IronPDF提供多種支援方案,包括專門的支援團隊用於處理問題和技術問題。 他們提供電子郵件支援並在開發者論壇具持續活動,提供解決方案和建議。您也可以使用網站的即時支援選項聯繫即時支援代理。
9.2 JSReport .NET文件質量及可用性
JSReport .NET以其廣泛和維護良好的文件而自豪。 文件涵蓋從基礎設置到高級使用場景的廣泛話題,並包含程式碼片段及實施範例。 其結構合乎邏輯,便於瀏覽和查找相關資訊。 線上資源還包括全面的API參考,確保開發者獲得有關工具能力的詳細資訊。
9.2.1 支援方案
JSReport .NET提供多樣的支援方案。 他們有可通過電子郵件聯繫的專門支援團隊,並在GitHub上保持活躍,提供報告問題和功能請求的平台。
10. 許可模式
10.1 IronPDF的授權

IronPDF提供三種不同的定價選擇,以適應不同的使用水平和預算需求:
Lite版:價格為$999,是雲端部署的一次性費用。 它專為較小的項目或剛剛開始處理PDF的團隊設計。
Professional版:價格為$1,499,也是一次性雲端部署費用,適合需要更多高級功能和能力的專業開發者。
Unlimited版:最全面的套件,價格為$2,999,為雲端部署的一次性費用。 它對大規模企業使用而言是理想選擇,提供廣泛功能且無使用限制。
10.2 JSReport .NET許可

JSReport .NET提供靈活的授權選項,包括基於訂閱和永久許可的選擇:
免費授權:這提供了最高支持5個報告模板的完全功能實例。 不需要許可金鑰,適合小型項目或評估用途。
企業訂閱:價格為每年395美元,這個計劃提供完全功能的單個JSReport實例,沒有限制並包括更新。 它對需要強大報告解決方案的個體企業而言理想。
企業規模訂閱:每年1295美元,這個計劃最適合大規模部署,提供單一授權金鑰,對無限數量實例有效。 此計畫包括更新且免版稅,適用於運行多個實例或作為另一產品的一部分部署給多個客戶的組織。
11. 結論
總之,儘管IronPDF和JSReport .NET在各自領域都很有價值,但是IronPDF由於其全面的PDF操作能力而略佔優勢。 它在如PDF/A合規、高級編輯和安全功能等方面表現出色,使其成為.NET環境中處理PDF細節的更有多功能的工具。 JSReport .NET,憑藉其在動態報告生成和模板方面的強項,則在以報告為中心的任務中效率極高。 然而,對於大多數需要詳細和多樣PDF處理和操作的場景,IronPDF成為更佳的選擇。
IronPDF提供免費開發者授權和免費試用。 Iron Software提供一個稱為Iron Suite的全面套裝,包括IronBarcode、IronXL、IronQR、IronOCR、IronPDF,以及IronWebScraper,價格為2個軟體,為尋求各種功能的開發者提供巨大價值。
最終,兩者之間的選擇取決於專案或開發者的特定需求和環境。
常見問題
我如何在 .NET 應用程式中將 HTML 轉換為 PDF?
您可以使用 IronPDF 的 RenderHtmlAsPdf 方法將 HTML 字串轉換為 PDF 文件。另外,IronPDF 支援使用 RenderHtmlFileAsPdf 方法將整個 HTML 文件轉換為 PDF。
using IronPDF 進行 ASP.NET 整合的優勢是什麼?
IronPDF 能夠與 ASP.NET 無縫整合,讓開發者以最少的編碼將 ASPX 頁面轉換為 PDF。這種整合對於從現有的網頁應用程式生成 PDF 報告特別有利。
IronPDF 能夠處理 PDF 的安全功能嗎?
是的,IronPDF 包含強大的安全功能,例如密碼保護、加密和設置 PDF 文件的許可權,這對於保護敏感資訊至關重要。
IronPDF 具有哪些功能,使其適合 HTML 到 PDF 的轉換?
IronPDF 以其易用性和高效能著稱於 HTML 到 PDF 的轉換。它支援先進功能,如 CSS 渲染、JavaScript 執行以及自訂的頁眉和頁腳。
JSReport SDK for .NET Core 的關鍵功能有哪些?
JSReport SDK for .NET Core 提供功能,如用於轉換 MVC 檢視輸出的中介軟體過濾器、與遠端實例的相容性、使用 OnAfterRender 鉤子的進階響應處理,並能夠從原始 HTML 中渲染報告。
JSReport 如何透過模板增強報告生成?
JSReport 支援各種模板引擎,使得報告設計更為複雜且靈活。它還提供調度和自動化功能,以便常規報告生成,提高生產力。
在 Docker 環境中使用 JSReport 的好處是什麼?
JSReport .NET 可有效與遠端 JSReport 實例整合,這對於在 Docker 環境中運行 JSReport 而置於獨立容器中的情形是有益的。這種設置促進了與 .NET Core 應用程式的高效協調。
IronPDF 提供哪些授權選項?
IronPDF 提供多種授權選項:小型專案使用的 Lite 版本、具有進階功能的 Professional 版本,以及大規模企業使用的 Unlimited 版本,滿足不同的專案需求。



