IronPDF對比GemBox.Pdf:完整.NET PDF庫比較指南,用於HTML轉PDF轉換
在開發需要PDF生成和操作的.NET應用程式時,選擇合適的C# PDF程式庫可顯著影響專案的成功。 這篇全面的比較檢視IronPDF和GemBox.Pdf這兩個著名的.NET PDF程式庫,以幫助開發者根據功能、效能、定價和現實場景做出明智的決定。
快速比較概覽
| 類別 | 功能/方面 | IronPDF | GemBox.Pdf | 關鍵優勢 |
|---|---|---|---|---|
| 核心架構 | 設計理念 | HTML優先,Chrome渲染 | PDF原生操作 | 依具體情況而定 |
| API複雜性 | 簡單的方法如RenderHtmlAsPdf() |
低層次PDF物件 | IronPDF:更快的開發 | |
| 學習曲線 | 1-2天的典型時間 | 通常3-5天 | IronPDF:更快適應 | |
| 平台支持 | 跨平台 | Windows、Linux、macOS、Docker | Windows, Linux, macOS, Android, iOS | GemBox: 移動端支援 |
| .NET版本 | .NET 10、9、8、7、6、5、Core 3.1+,Framework 4.6.2+ | .NET 6, Standard 2.0, Framework 3.5+ | IronPDF: 最新.NET支援 | |
| 雲平台 | Azure/AWS優化 | 標準雲端支援 | IronPDF:雲端就緒 | |
| HTML到PDF | 渲染引擎 | 完整的Chrome V8引擎 | 基於Chromium的引擎 | 雙方: Chromium渲染 |
| CSS3/HTML5支持 | 完整支援 | HTML5/CSS3支援 | 雙方: 現代網頁標準 | |
| JavaScript執行 | 完整的JavaScript支持 | 支援JavaScript執行 | 雙方: 動態內容 | |
| 渲染速度 | ~125ms通常 | 基於Chromium的渲染 | IronPDF: 有紀錄的渲染時間 | |
| 開發者體驗 | 程式碼範例 | 100多個即用範例 | 100+範例可用 | 雙方: 廣泛的資源 |
| 文件 | 教程,操作指南,影片 | API文件專注 | IronPDF:多重學習路徑 | |
| 內容操作 | 合併/拆分PDF | 內建方法 | 內建方法 | 雙方: 標準功能 |
| 文字擷取 | Unicode支援,OCR整合 | Unicode支援,內建OCR | GemBox: 內建OCR | |
| 表單支援 | HTML表單到PDF表單 | 建立、填充、攤平成表單 | 依具體情況而定 | |
| 性能指標 | 記憶體使用 | 典型情況下小於10MB | 低記憶體佔用 | 雙方: 高效 |
| 多執行緒支持 | 本機async/await優化 | 執行緒安全操作 | IronPDF:更好的非同步支持 | |
| Security & Encryption | 加密等級 | AES-256,自訂處理器 | AES-256標準 | 兩者:業界標準 |
| 數位簽名 | 整合的,可視簽名 | 數位簽名支援 | 雙方: 簽名支援 | |
| Licensing & Pricing | 入門級 | Lite:$999(1位開發者,1個專案) | Single Dev: $890 (1 開發者,無限專案) | IronPDF: 較低的進入成本 |
| 再分發 | +$1,999免版稅 | 包含,無限佈署 | GemBox: 更好的佈署條款 | |
| 套件選項 | Iron Suite: $2,998 (9 個產品) | GemBox Bundle: $2,200 (6 個產品, 1 開發者) | IronPDF: 更好的套裝價值 | |
| 支援 | 是否包含支援 | 是,24/5工程支援 | 是的,1 年專業支援 | 雙方: 良好的支援 |
| 回應時間 | 24-48小時典型 | 在1個工作天內 | 雙方: 快速反應 | |
| 最佳用途 | 用例 | HTML轉PDF,網頁應用,報表 | PDF操作,表單,OCR | 依具體情況而定 |
什麼是IronPDF程式庫?
IronPDF 脫穎而出,成為一個專門設計用於為開發人員簡化HTML轉PDF轉換的綜合.NET PDF程式庫。 IronPDF 基於其核心的 Chrome 渲染引擎構建,轉變開發者在 C#、F# 和 VB.NET 應用程式中處理PDF生成的方式。
這個程式庫的理念集中在利用現有的網頁開發技能。 不用學習複雜的PDF API,開發者可以使用熟悉的 HTML, CSS 和 JavaScript 來建立複雜的 PDF 文件。 這種方法大大減少了開發時間,同時確保了像素完美的渲染,符合現代網頁標準。
IronPDF的核心功能
IronPDF提供了廣泛的功能集合,幾乎涵蓋了開發者可能遇到的每一個PDF相關任務:
HTML到PDF轉換的卓越
- Chrome V8引擎: 使用和Google Chrome一樣的引擎渲染HTML,確保98%以上的瀏覽器契合度
- 完整CSS3/HTML5支持: 完全支持現代網頁標準,包括flexbox、grid和動畫
- JavaScript執行: 在渲染前處理JavaScript,完美捕捉動態內容
- 響應式設計: 處理響應式佈局,具有可自定義的視窗設置
- 網頁字型支持: 准確地渲染Google字型、自定字型和圖示字型
高級PDF操作
- 合併和拆分PDF:: 通過簡單的方法調用來合併多個PDF或提取特定頁面
- 數位簽名:: 使用證書支持應用加密簽名
- 表單管理:: 從HTML建立可填寫表單或處理現有的PDF表單
- 水印和印章:: 新增帶有透明度控制的文字或圖像水印
- 頁眉和頁腳:: 動態頁眉/頁腳與頁碼
安全性和合規性
IronPDF程式碼範例:使用高級功能的HTML到PDF
using IronPdf;
using IronPdf.Rendering;
// Configure the Chrome renderer with advanced options
var renderer = new ChromePdfRenderer
{
RenderingOptions = new ChromePdfRenderOptions
{
// Set paper orientation and size
PaperOrientation = PdfPaperOrientation.Portrait,
PaperSize = PdfPaperSize.A4,
// Configure margins (in millimeters)
MarginTop = 25,
MarginBottom = 25,
MarginLeft = 20,
MarginRight = 20,
// Enable JavaScript execution
EnableJavaScript = true,
RenderDelay = 1000, // Wait 1 second for JS to complete
// Print background colors and images
PrintHtmlBackgrounds = true,
// Create PDF forms from HTML form elements
CreatePdfFormsFromHtml = true,
// Custom header and footer
HtmlHeader = new HtmlHeaderFooter
{
Height = 20,
HtmlFragment = "<div style='text-align: center; font-size: 12px;'>Company Report - {page} of {total-pages}</div>",
DrawDividerLine = true
},
HtmlFooter = new HtmlHeaderFooter
{
Height = 15,
HtmlFragment = "<div style='text-align: center; font-size: 10px;'>© 2025 Company Name. Confidential.</div>"
}
}
};
// Convert complex HTML with CSS and JavaScript
string htmlContent = @"
<!DOCTYPE html>
<html>
<head>
<style>
body { font-family: 'Segoe UI', Arial, sans-serif; line-height: 1.6; }
.invoice-header {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
padding: 30px;
border-radius: 10px;
margin-bottom: 30px;
}
.data-table {
width: 100%;
border-collapse: collapse;
margin-top: 20px;
}
.data-table th {
background-color: #f8f9fa;
padding: 12px;
text-align: left;
border-bottom: 2px solid #dee2e6;
}
.data-table td {
padding: 10px;
border-bottom: 1px solid #dee2e6;
}
.total-section {
margin-top: 30px;
text-align: right;
font-size: 18px;
font-weight: bold;
}
@media print {
.no-print { display: none; }
}
</style>
</head>
<body>
<div class='invoice-header'>
<h1>Invoice #INV-2025-001</h1>
<p>Date: <span id='current-date'></span></p>
</div>
<table class='data-table'>
<thead>
<tr>
<th>Item Description</th>
<th>Quantity</th>
<th>Unit Price</th>
<th>Total</th>
</tr>
</thead>
<tbody>
<tr>
<td>Professional PDF Library License</td>
<td>1</td>
<td>$999.00</td>
<td>$999.00</td>
</tr>
<tr>
<td>Priority Support (1 Year)</td>
<td>1</td>
<td>$299.00</td>
<td>$299.00</td>
</tr>
</tbody>
</table>
<div class='total-section'>
<p>Subtotal: $1,048.00</p>
<p>Tax (8%): $83.84</p>
<p style='color: #667eea; font-size: 24px;'>Total: $1,131.84</p>
</div>
<script>
// Dynamic date insertion
document.getElementById('current-date').textContent = new Date().toLocaleDateString('en-US', {
year: 'numeric',
month: 'long',
day: 'numeric'
});
</script>
</body>
</html>";
// Render the HTML to PDF
PdfDocument pdf = renderer.RenderHtmlAsPdf(htmlContent);
// Apply additional security settings
pdf.SecuritySettings.OwnerPassword = "admin123";
pdf.SecuritySettings.UserPassword = "user123";
pdf.SecuritySettings.AllowUserPrinting = PdfPrintSecurity.NoPrint;
pdf.SecuritySettings.AllowUserCopyPasteContent = false;
pdf.SecuritySettings.AllowUserAnnotations = false;
pdf.SecuritySettings.AllowUserFormData = true;
// Add metadata
pdf.MetaData.Author = "Invoice System";
pdf.MetaData.Title = "Invoice INV-2025-001";
pdf.MetaData.Subject = "Customer Invoice";
pdf.MetaData.Keywords = "invoice, payment, 2025";
pdf.MetaData.CreationDate = DateTime.Now;
// Save the PDF
pdf.SaveAs("invoice-2025-001.pdf");
// Optional: Save as PDF/A for archival
pdf.SaveAsPdfA("invoice-2025-001-archive.pdf", PdfAVersions.PdfA3);
using IronPdf;
using IronPdf.Rendering;
// Configure the Chrome renderer with advanced options
var renderer = new ChromePdfRenderer
{
RenderingOptions = new ChromePdfRenderOptions
{
// Set paper orientation and size
PaperOrientation = PdfPaperOrientation.Portrait,
PaperSize = PdfPaperSize.A4,
// Configure margins (in millimeters)
MarginTop = 25,
MarginBottom = 25,
MarginLeft = 20,
MarginRight = 20,
// Enable JavaScript execution
EnableJavaScript = true,
RenderDelay = 1000, // Wait 1 second for JS to complete
// Print background colors and images
PrintHtmlBackgrounds = true,
// Create PDF forms from HTML form elements
CreatePdfFormsFromHtml = true,
// Custom header and footer
HtmlHeader = new HtmlHeaderFooter
{
Height = 20,
HtmlFragment = "<div style='text-align: center; font-size: 12px;'>Company Report - {page} of {total-pages}</div>",
DrawDividerLine = true
},
HtmlFooter = new HtmlHeaderFooter
{
Height = 15,
HtmlFragment = "<div style='text-align: center; font-size: 10px;'>© 2025 Company Name. Confidential.</div>"
}
}
};
// Convert complex HTML with CSS and JavaScript
string htmlContent = @"
<!DOCTYPE html>
<html>
<head>
<style>
body { font-family: 'Segoe UI', Arial, sans-serif; line-height: 1.6; }
.invoice-header {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
padding: 30px;
border-radius: 10px;
margin-bottom: 30px;
}
.data-table {
width: 100%;
border-collapse: collapse;
margin-top: 20px;
}
.data-table th {
background-color: #f8f9fa;
padding: 12px;
text-align: left;
border-bottom: 2px solid #dee2e6;
}
.data-table td {
padding: 10px;
border-bottom: 1px solid #dee2e6;
}
.total-section {
margin-top: 30px;
text-align: right;
font-size: 18px;
font-weight: bold;
}
@media print {
.no-print { display: none; }
}
</style>
</head>
<body>
<div class='invoice-header'>
<h1>Invoice #INV-2025-001</h1>
<p>Date: <span id='current-date'></span></p>
</div>
<table class='data-table'>
<thead>
<tr>
<th>Item Description</th>
<th>Quantity</th>
<th>Unit Price</th>
<th>Total</th>
</tr>
</thead>
<tbody>
<tr>
<td>Professional PDF Library License</td>
<td>1</td>
<td>$999.00</td>
<td>$999.00</td>
</tr>
<tr>
<td>Priority Support (1 Year)</td>
<td>1</td>
<td>$299.00</td>
<td>$299.00</td>
</tr>
</tbody>
</table>
<div class='total-section'>
<p>Subtotal: $1,048.00</p>
<p>Tax (8%): $83.84</p>
<p style='color: #667eea; font-size: 24px;'>Total: $1,131.84</p>
</div>
<script>
// Dynamic date insertion
document.getElementById('current-date').textContent = new Date().toLocaleDateString('en-US', {
year: 'numeric',
month: 'long',
day: 'numeric'
});
</script>
</body>
</html>";
// Render the HTML to PDF
PdfDocument pdf = renderer.RenderHtmlAsPdf(htmlContent);
// Apply additional security settings
pdf.SecuritySettings.OwnerPassword = "admin123";
pdf.SecuritySettings.UserPassword = "user123";
pdf.SecuritySettings.AllowUserPrinting = PdfPrintSecurity.NoPrint;
pdf.SecuritySettings.AllowUserCopyPasteContent = false;
pdf.SecuritySettings.AllowUserAnnotations = false;
pdf.SecuritySettings.AllowUserFormData = true;
// Add metadata
pdf.MetaData.Author = "Invoice System";
pdf.MetaData.Title = "Invoice INV-2025-001";
pdf.MetaData.Subject = "Customer Invoice";
pdf.MetaData.Keywords = "invoice, payment, 2025";
pdf.MetaData.CreationDate = DateTime.Now;
// Save the PDF
pdf.SaveAs("invoice-2025-001.pdf");
// Optional: Save as PDF/A for archival
pdf.SaveAsPdfA("invoice-2025-001-archive.pdf", PdfAVersions.PdfA3);
Imports IronPdf
Imports IronPdf.Rendering
' Configure the Chrome renderer with advanced options
Dim renderer As New ChromePdfRenderer With {
.RenderingOptions = New ChromePdfRenderOptions With {
' Set paper orientation and size
.PaperOrientation = PdfPaperOrientation.Portrait,
.PaperSize = PdfPaperSize.A4,
' Configure margins (in millimeters)
.MarginTop = 25,
.MarginBottom = 25,
.MarginLeft = 20,
.MarginRight = 20,
' Enable JavaScript execution
.EnableJavaScript = True,
.RenderDelay = 1000, ' Wait 1 second for JS to complete
' Print background colors and images
.PrintHtmlBackgrounds = True,
' Create PDF forms from HTML form elements
.CreatePdfFormsFromHtml = True,
' Custom header and footer
.HtmlHeader = New HtmlHeaderFooter With {
.Height = 20,
.HtmlFragment = "<div style='text-align: center; font-size: 12px;'>Company Report - {page} of {total-pages}</div>",
.DrawDividerLine = True
},
.HtmlFooter = New HtmlHeaderFooter With {
.Height = 15,
.HtmlFragment = "<div style='text-align: center; font-size: 10px;'>© 2025 Company Name. Confidential.</div>"
}
}
}
' Convert complex HTML with CSS and JavaScript
Dim htmlContent As String = "
<!DOCTYPE html>
<html>
<head>
<style>
body { font-family: 'Segoe UI', Arial, sans-serif; line-height: 1.6; }
.invoice-header {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
padding: 30px;
border-radius: 10px;
margin-bottom: 30px;
}
.data-table {
width: 100%;
border-collapse: collapse;
margin-top: 20px;
}
.data-table th {
background-color: #f8f9fa;
padding: 12px;
text-align: left;
border-bottom: 2px solid #dee2e6;
}
.data-table td {
padding: 10px;
border-bottom: 1px solid #dee2e6;
}
.total-section {
margin-top: 30px;
text-align: right;
font-size: 18px;
font-weight: bold;
}
@media print {
.no-print { display: none; }
}
</style>
</head>
<body>
<div class='invoice-header'>
<h1>Invoice #INV-2025-001</h1>
<p>Date: <span id='current-date'></span></p>
</div>
<table class='data-table'>
<thead>
<tr>
<th>Item Description</th>
<th>Quantity</th>
<th>Unit Price</th>
<th>Total</th>
</tr>
</thead>
<tbody>
<tr>
<td>Professional PDF Library License</td>
<td>1</td>
<td>$999.00</td>
<td>$999.00</td>
</tr>
<tr>
<td>Priority Support (1 Year)</td>
<td>1</td>
<td>$299.00</td>
<td>$299.00</td>
</tr>
</tbody>
</table>
<div class='total-section'>
<p>Subtotal: $1,048.00</p>
<p>Tax (8%): $83.84</p>
<p style='color: #667eea; font-size: 24px;'>Total: $1,131.84</p>
</div>
<script>
// Dynamic date insertion
document.getElementById('current-date').textContent = new Date().toLocaleDateString('en-US', {
year: 'numeric',
month: 'long',
day: 'numeric'
});
</script>
</body>
</html>"
' Render the HTML to PDF
Dim pdf As PdfDocument = renderer.RenderHtmlAsPdf(htmlContent)
' Apply additional security settings
pdf.SecuritySettings.OwnerPassword = "admin123"
pdf.SecuritySettings.UserPassword = "user123"
pdf.SecuritySettings.AllowUserPrinting = PdfPrintSecurity.NoPrint
pdf.SecuritySettings.AllowUserCopyPasteContent = False
pdf.SecuritySettings.AllowUserAnnotations = False
pdf.SecuritySettings.AllowUserFormData = True
' Add metadata
pdf.MetaData.Author = "Invoice System"
pdf.MetaData.Title = "Invoice INV-2025-001"
pdf.MetaData.Subject = "Customer Invoice"
pdf.MetaData.Keywords = "invoice, payment, 2025"
pdf.MetaData.CreationDate = DateTime.Now
' Save the PDF
pdf.SaveAs("invoice-2025-001.pdf")
' Optional: Save as PDF/A for archival
pdf.SaveAsPdfA("invoice-2025-001-archive.pdf", PdfAVersions.PdfA3)
此範例展示了IronPDF應對複雜HTML佈局的能力,包括漸變、表格、動態JavaScript內容和高級PDF功能,如安全設置和元資料。 該程式庫無縫處理所有內容,生成專業的PDF,完全匹配HTML設計。
什麼是GemBox.Pdf庫?
GemBox.Pdf代表了不同的.NET PDF操作方法。 GemBox.Pdf專注於低層次PDF操作和直接的PDF操作,而非HTML到PDF轉換。 這使得它特別適合需要精確控制PDF結構和內容的場景。
該程式庫擅長處理現有的PDF文件,提供強大的功能以便精細地讀取、編輯和操作PDF。 GemBox.Pdf不依賴於Adobe Acrobat,在多種環境中進行佈署十分簡單。
GemBox.Pdf的核心功能
GemBox.Pdf提供了全面的PDF操作功能:
PDF文件操作
- 讀取和寫入PDFs: 直接存取PDF的結構和內容
- 合併和拆分: 合併多個PDF或提取特定頁面
- 頁面克隆: 在不同的PDF文件中導入頁面
- 頁面管理: 程式化地新增、刪除或重新排列頁面
內容擷取和操作
- 文字擷取: 提取帶有定位資訊的Unicode文字
- 圖像擷取: 從PDF文件中取出嵌入的圖像
- OCR支持: 內建的光學字元識別,適用於掃描文件
- 內容修訂: 永久刪除敏感資訊
表單和互動性
- 交互式表單: 创建、填充、平展和匯出PDF表單
- 表單欄位管理: 对所有表單欄位型別進行程式化存取
- 註釋: 新增超連結和其他PDF註釋
圖形和視覺元素
- 繪圖操作: 新增文字、圖像和向量圖形
- 形狀和路徑: 建立複雜的向量繪圖
- 水印: 應用文字和圖像水印
- 內容組: 將內容整理成邏輯組
GemBox.Pdf程式碼範例:PDF操作和表單
using GemBox.Pdf;
using GemBox.Pdf.Content;
using GemBox.Pdf.Forms;
using GemBox.Pdf.Security;
// Set license (use FREE-LIMITED-KEY for evaluation)
ComponentInfo.SetLicense("FREE-LIMITED-KEY");
// Create a new PDF document from scratch
using (var document = new PdfDocument())
{
// Add a page with custom size
var page = document.Pages.Add();
// Create formatted text with multiple styles
using (var formattedText = new PdfFormattedText())
{
formattedText.FontSize = 24;
formattedText.FontFamily = new PdfFontFamily("Arial");
formattedText.Color = PdfColor.FromRgb(0.2, 0.2, 0.6);
formattedText.AppendLine("GemBox.Pdf Document Example");
formattedText.FontSize = 12;
formattedText.Color = PdfColor.FromRgb(0, 0, 0);
formattedText.AppendLine("This document demonstrates PDF creation and manipulation features.");
// Draw text to the page
page.Content.DrawText(formattedText, new PdfPoint(50, 700));
}
// Add a form to the document
var form = document.Form;
// Create text field
var textField = form.Fields.AddText(page, 50, 600, 200, 30);
textField.Name = "CustomerName";
textField.Value = "Enter your name";
textField.Format.Fill.Color = PdfColor.FromRgb(0.95, 0.95, 0.95);
// Create checkbox
var checkBox = form.Fields.AddCheck(page, 50, 550, 20, 20);
checkBox.Name = "Agreement";
checkBox.Checked = false;
// Add descriptive text next to checkbox
using (var checkboxLabel = new PdfFormattedText())
{
checkboxLabel.Append("I agree to the terms and conditions");
page.Content.DrawText(checkboxLabel, new PdfPoint(80, 555));
}
// Create submit button
var submitButton = form.Fields.AddButton(page, 50, 500, 100, 30);
submitButton.Name = "Submit";
submitButton.Actions.Activate = PdfActionType.Named;
// Add button appearance
using (var buttonText = new PdfFormattedText())
{
buttonText.Append("Submit Form");
buttonText.FontSize = 14;
buttonText.Color = PdfColor.FromRgb(1, 1, 1);
// Create button appearance stream
var appearance = submitButton.Appearance.Normal;
appearance.Fill.Color = PdfColor.FromRgb(0.2, 0.4, 0.8);
appearance.Stroke.Color = PdfColor.FromRgb(0.1, 0.2, 0.4);
appearance.Stroke.Width = 1;
// Draw button background
appearance.DrawRectangle(new PdfPoint(0, 0), new PdfSize(100, 30), true, true);
// Draw button text
appearance.DrawText(buttonText, new PdfPoint(20, 10));
}
// Add a table using low-level graphics
var tableTop = 400;
var tableLeft = 50;
var cellWidth = 150;
var cellHeight = 30;
// Draw table headers
page.Content.DrawRectangle(new PdfPoint(tableLeft, tableTop),
new PdfSize(cellWidth * 3, cellHeight), true, true);
using (var headerText = new PdfFormattedText())
{
headerText.FontSize = 12;
headerText.Color = PdfColor.FromRgb(1, 1, 1);
headerText.Append("Product");
page.Content.DrawText(headerText, new PdfPoint(tableLeft + 10, tableTop + 10));
headerText.Clear();
headerText.Append("Quantity");
page.Content.DrawText(headerText, new PdfPoint(tableLeft + cellWidth + 10, tableTop + 10));
headerText.Clear();
headerText.Append("Price");
page.Content.DrawText(headerText, new PdfPoint(tableLeft + cellWidth * 2 + 10, tableTop + 10));
}
// Draw table data rows
var rowData = new[]
{
new { Product = "PDF Library", Quantity = "1", Price = "$890" },
new { Product = "Support Plan", Quantity = "1", Price = "$299" },
new { Product = "Training", Quantity = "2", Price = "$500" }
};
var currentY = tableTop - cellHeight;
foreach (var row in rowData)
{
// Draw cell borders
page.Content.DrawRectangle(new PdfPoint(tableLeft, currentY),
new PdfSize(cellWidth, cellHeight), false, true);
page.Content.DrawRectangle(new PdfPoint(tableLeft + cellWidth, currentY),
new PdfSize(cellWidth, cellHeight), false, true);
page.Content.DrawRectangle(new PdfPoint(tableLeft + cellWidth * 2, currentY),
new PdfSize(cellWidth, cellHeight), false, true);
// Draw cell content
using (var cellText = new PdfFormattedText())
{
cellText.FontSize = 11;
cellText.Append(row.Product);
page.Content.DrawText(cellText, new PdfPoint(tableLeft + 10, currentY + 10));
cellText.Clear();
cellText.Append(row.Quantity);
page.Content.DrawText(cellText, new PdfPoint(tableLeft + cellWidth + 10, currentY + 10));
cellText.Clear();
cellText.Append(row.Price);
page.Content.DrawText(cellText, new PdfPoint(tableLeft + cellWidth * 2 + 10, currentY + 10));
}
currentY -= cellHeight;
}
// Apply security settings
var securitySettings = document.SecuritySettings;
securitySettings.DocumentOpenPassword = "user123";
securitySettings.PermissionsPassword = "owner123";
securitySettings.Permissions = PdfPermissions.AllowPrint | PdfPermissions.AllowFormFill;
// Save the document
document.Save("gembox-example.pdf");
}
// Example: Manipulating existing PDF
using (var existingDoc = PdfDocument.Load("existing-document.pdf"))
{
// Extract text from first page
var page = existingDoc.Pages[0];
var text = page.Content.GetText();
Console.WriteLine($"Extracted text: {text}");
// Add watermark to all pages
foreach (var p in existingDoc.Pages)
{
using (var watermark = new PdfFormattedText())
{
watermark.Append("CONFIDENTIAL");
watermark.FontSize = 50;
watermark.Color = PdfColor.FromRgb(0.5, 0.5, 0.5);
watermark.Opacity = 0.3;
// Calculate center position
var pageWidth = p.MediaBox.Width;
var pageHeight = p.MediaBox.Height;
var textWidth = watermark.Width;
var textHeight = watermark.Height;
var x = (pageWidth - textWidth) / 2;
var y = (pageHeight - textHeight) / 2;
// Draw watermark diagonally
p.Content.SaveGraphicsState();
p.Content.SetTransform(1, 0, 0, 1, x, y);
p.Content.SetTransform(0.7071, 0.7071, -0.7071, 0.7071, 0, 0);
p.Content.DrawText(watermark, new PdfPoint(0, 0));
p.Content.RestoreGraphicsState();
}
}
existingDoc.Save("watermarked-document.pdf");
}
using GemBox.Pdf;
using GemBox.Pdf.Content;
using GemBox.Pdf.Forms;
using GemBox.Pdf.Security;
// Set license (use FREE-LIMITED-KEY for evaluation)
ComponentInfo.SetLicense("FREE-LIMITED-KEY");
// Create a new PDF document from scratch
using (var document = new PdfDocument())
{
// Add a page with custom size
var page = document.Pages.Add();
// Create formatted text with multiple styles
using (var formattedText = new PdfFormattedText())
{
formattedText.FontSize = 24;
formattedText.FontFamily = new PdfFontFamily("Arial");
formattedText.Color = PdfColor.FromRgb(0.2, 0.2, 0.6);
formattedText.AppendLine("GemBox.Pdf Document Example");
formattedText.FontSize = 12;
formattedText.Color = PdfColor.FromRgb(0, 0, 0);
formattedText.AppendLine("This document demonstrates PDF creation and manipulation features.");
// Draw text to the page
page.Content.DrawText(formattedText, new PdfPoint(50, 700));
}
// Add a form to the document
var form = document.Form;
// Create text field
var textField = form.Fields.AddText(page, 50, 600, 200, 30);
textField.Name = "CustomerName";
textField.Value = "Enter your name";
textField.Format.Fill.Color = PdfColor.FromRgb(0.95, 0.95, 0.95);
// Create checkbox
var checkBox = form.Fields.AddCheck(page, 50, 550, 20, 20);
checkBox.Name = "Agreement";
checkBox.Checked = false;
// Add descriptive text next to checkbox
using (var checkboxLabel = new PdfFormattedText())
{
checkboxLabel.Append("I agree to the terms and conditions");
page.Content.DrawText(checkboxLabel, new PdfPoint(80, 555));
}
// Create submit button
var submitButton = form.Fields.AddButton(page, 50, 500, 100, 30);
submitButton.Name = "Submit";
submitButton.Actions.Activate = PdfActionType.Named;
// Add button appearance
using (var buttonText = new PdfFormattedText())
{
buttonText.Append("Submit Form");
buttonText.FontSize = 14;
buttonText.Color = PdfColor.FromRgb(1, 1, 1);
// Create button appearance stream
var appearance = submitButton.Appearance.Normal;
appearance.Fill.Color = PdfColor.FromRgb(0.2, 0.4, 0.8);
appearance.Stroke.Color = PdfColor.FromRgb(0.1, 0.2, 0.4);
appearance.Stroke.Width = 1;
// Draw button background
appearance.DrawRectangle(new PdfPoint(0, 0), new PdfSize(100, 30), true, true);
// Draw button text
appearance.DrawText(buttonText, new PdfPoint(20, 10));
}
// Add a table using low-level graphics
var tableTop = 400;
var tableLeft = 50;
var cellWidth = 150;
var cellHeight = 30;
// Draw table headers
page.Content.DrawRectangle(new PdfPoint(tableLeft, tableTop),
new PdfSize(cellWidth * 3, cellHeight), true, true);
using (var headerText = new PdfFormattedText())
{
headerText.FontSize = 12;
headerText.Color = PdfColor.FromRgb(1, 1, 1);
headerText.Append("Product");
page.Content.DrawText(headerText, new PdfPoint(tableLeft + 10, tableTop + 10));
headerText.Clear();
headerText.Append("Quantity");
page.Content.DrawText(headerText, new PdfPoint(tableLeft + cellWidth + 10, tableTop + 10));
headerText.Clear();
headerText.Append("Price");
page.Content.DrawText(headerText, new PdfPoint(tableLeft + cellWidth * 2 + 10, tableTop + 10));
}
// Draw table data rows
var rowData = new[]
{
new { Product = "PDF Library", Quantity = "1", Price = "$890" },
new { Product = "Support Plan", Quantity = "1", Price = "$299" },
new { Product = "Training", Quantity = "2", Price = "$500" }
};
var currentY = tableTop - cellHeight;
foreach (var row in rowData)
{
// Draw cell borders
page.Content.DrawRectangle(new PdfPoint(tableLeft, currentY),
new PdfSize(cellWidth, cellHeight), false, true);
page.Content.DrawRectangle(new PdfPoint(tableLeft + cellWidth, currentY),
new PdfSize(cellWidth, cellHeight), false, true);
page.Content.DrawRectangle(new PdfPoint(tableLeft + cellWidth * 2, currentY),
new PdfSize(cellWidth, cellHeight), false, true);
// Draw cell content
using (var cellText = new PdfFormattedText())
{
cellText.FontSize = 11;
cellText.Append(row.Product);
page.Content.DrawText(cellText, new PdfPoint(tableLeft + 10, currentY + 10));
cellText.Clear();
cellText.Append(row.Quantity);
page.Content.DrawText(cellText, new PdfPoint(tableLeft + cellWidth + 10, currentY + 10));
cellText.Clear();
cellText.Append(row.Price);
page.Content.DrawText(cellText, new PdfPoint(tableLeft + cellWidth * 2 + 10, currentY + 10));
}
currentY -= cellHeight;
}
// Apply security settings
var securitySettings = document.SecuritySettings;
securitySettings.DocumentOpenPassword = "user123";
securitySettings.PermissionsPassword = "owner123";
securitySettings.Permissions = PdfPermissions.AllowPrint | PdfPermissions.AllowFormFill;
// Save the document
document.Save("gembox-example.pdf");
}
// Example: Manipulating existing PDF
using (var existingDoc = PdfDocument.Load("existing-document.pdf"))
{
// Extract text from first page
var page = existingDoc.Pages[0];
var text = page.Content.GetText();
Console.WriteLine($"Extracted text: {text}");
// Add watermark to all pages
foreach (var p in existingDoc.Pages)
{
using (var watermark = new PdfFormattedText())
{
watermark.Append("CONFIDENTIAL");
watermark.FontSize = 50;
watermark.Color = PdfColor.FromRgb(0.5, 0.5, 0.5);
watermark.Opacity = 0.3;
// Calculate center position
var pageWidth = p.MediaBox.Width;
var pageHeight = p.MediaBox.Height;
var textWidth = watermark.Width;
var textHeight = watermark.Height;
var x = (pageWidth - textWidth) / 2;
var y = (pageHeight - textHeight) / 2;
// Draw watermark diagonally
p.Content.SaveGraphicsState();
p.Content.SetTransform(1, 0, 0, 1, x, y);
p.Content.SetTransform(0.7071, 0.7071, -0.7071, 0.7071, 0, 0);
p.Content.DrawText(watermark, new PdfPoint(0, 0));
p.Content.RestoreGraphicsState();
}
}
existingDoc.Save("watermarked-document.pdf");
}
Imports GemBox.Pdf
Imports GemBox.Pdf.Content
Imports GemBox.Pdf.Forms
Imports GemBox.Pdf.Security
' Set license (use FREE-LIMITED-KEY for evaluation)
ComponentInfo.SetLicense("FREE-LIMITED-KEY")
' Create a new PDF document from scratch
Using document = New PdfDocument()
' Add a page with custom size
Dim page = document.Pages.Add()
' Create formatted text with multiple styles
Using formattedText = New PdfFormattedText()
formattedText.FontSize = 24
formattedText.FontFamily = New PdfFontFamily("Arial")
formattedText.Color = PdfColor.FromRgb(0.2, 0.2, 0.6)
formattedText.AppendLine("GemBox.Pdf Document Example")
formattedText.FontSize = 12
formattedText.Color = PdfColor.FromRgb(0, 0, 0)
formattedText.AppendLine("This document demonstrates PDF creation and manipulation features.")
' Draw text to the page
page.Content.DrawText(formattedText, New PdfPoint(50, 700))
End Using
' Add a form to the document
Dim form = document.Form
' Create text field
Dim textField = form.Fields.AddText(page, 50, 600, 200, 30)
textField.Name = "CustomerName"
textField.Value = "Enter your name"
textField.Format.Fill.Color = PdfColor.FromRgb(0.95, 0.95, 0.95)
' Create checkbox
Dim checkBox = form.Fields.AddCheck(page, 50, 550, 20, 20)
checkBox.Name = "Agreement"
checkBox.Checked = False
' Add descriptive text next to checkbox
Using checkboxLabel = New PdfFormattedText()
checkboxLabel.Append("I agree to the terms and conditions")
page.Content.DrawText(checkboxLabel, New PdfPoint(80, 555))
End Using
' Create submit button
Dim submitButton = form.Fields.AddButton(page, 50, 500, 100, 30)
submitButton.Name = "Submit"
submitButton.Actions.Activate = PdfActionType.Named
' Add button appearance
Using buttonText = New PdfFormattedText()
buttonText.Append("Submit Form")
buttonText.FontSize = 14
buttonText.Color = PdfColor.FromRgb(1, 1, 1)
' Create button appearance stream
Dim appearance = submitButton.Appearance.Normal
appearance.Fill.Color = PdfColor.FromRgb(0.2, 0.4, 0.8)
appearance.Stroke.Color = PdfColor.FromRgb(0.1, 0.2, 0.4)
appearance.Stroke.Width = 1
' Draw button background
appearance.DrawRectangle(New PdfPoint(0, 0), New PdfSize(100, 30), True, True)
' Draw button text
appearance.DrawText(buttonText, New PdfPoint(20, 10))
End Using
' Add a table using low-level graphics
Dim tableTop = 400
Dim tableLeft = 50
Dim cellWidth = 150
Dim cellHeight = 30
' Draw table headers
page.Content.DrawRectangle(New PdfPoint(tableLeft, tableTop), New PdfSize(cellWidth * 3, cellHeight), True, True)
Using headerText = New PdfFormattedText()
headerText.FontSize = 12
headerText.Color = PdfColor.FromRgb(1, 1, 1)
headerText.Append("Product")
page.Content.DrawText(headerText, New PdfPoint(tableLeft + 10, tableTop + 10))
headerText.Clear()
headerText.Append("Quantity")
page.Content.DrawText(headerText, New PdfPoint(tableLeft + cellWidth + 10, tableTop + 10))
headerText.Clear()
headerText.Append("Price")
page.Content.DrawText(headerText, New PdfPoint(tableLeft + cellWidth * 2 + 10, tableTop + 10))
End Using
' Draw table data rows
Dim rowData = {
New With {
Key .Product = "PDF Library",
Key .Quantity = "1",
Key .Price = "$890"
},
New With {
Key .Product = "Support Plan",
Key .Quantity = "1",
Key .Price = "$299"
},
New With {
Key .Product = "Training",
Key .Quantity = "2",
Key .Price = "$500"
}
}
Dim currentY = tableTop - cellHeight
For Each row In rowData
' Draw cell borders
page.Content.DrawRectangle(New PdfPoint(tableLeft, currentY), New PdfSize(cellWidth, cellHeight), False, True)
page.Content.DrawRectangle(New PdfPoint(tableLeft + cellWidth, currentY), New PdfSize(cellWidth, cellHeight), False, True)
page.Content.DrawRectangle(New PdfPoint(tableLeft + cellWidth * 2, currentY), New PdfSize(cellWidth, cellHeight), False, True)
' Draw cell content
Using cellText = New PdfFormattedText()
cellText.FontSize = 11
cellText.Append(row.Product)
page.Content.DrawText(cellText, New PdfPoint(tableLeft + 10, currentY + 10))
cellText.Clear()
cellText.Append(row.Quantity)
page.Content.DrawText(cellText, New PdfPoint(tableLeft + cellWidth + 10, currentY + 10))
cellText.Clear()
cellText.Append(row.Price)
page.Content.DrawText(cellText, New PdfPoint(tableLeft + cellWidth * 2 + 10, currentY + 10))
End Using
currentY -= cellHeight
Next row
' Apply security settings
Dim securitySettings = document.SecuritySettings
securitySettings.DocumentOpenPassword = "user123"
securitySettings.PermissionsPassword = "owner123"
securitySettings.Permissions = PdfPermissions.AllowPrint Or PdfPermissions.AllowFormFill
' Save the document
document.Save("gembox-example.pdf")
End Using
' Example: Manipulating existing PDF
Using existingDoc = PdfDocument.Load("existing-document.pdf")
' Extract text from first page
Dim page = existingDoc.Pages(0)
Dim text = page.Content.GetText()
Console.WriteLine($"Extracted text: {text}")
' Add watermark to all pages
For Each p In existingDoc.Pages
Using watermark = New PdfFormattedText()
watermark.Append("CONFIDENTIAL")
watermark.FontSize = 50
watermark.Color = PdfColor.FromRgb(0.5, 0.5, 0.5)
watermark.Opacity = 0.3
' Calculate center position
Dim pageWidth = p.MediaBox.Width
Dim pageHeight = p.MediaBox.Height
Dim textWidth = watermark.Width
Dim textHeight = watermark.Height
Dim x = (pageWidth - textWidth) \ 2
Dim y = (pageHeight - textHeight) \ 2
' Draw watermark diagonally
p.Content.SaveGraphicsState()
p.Content.SetTransform(1, 0, 0, 1, x, y)
p.Content.SetTransform(0.7071, 0.7071, -0.7071, 0.7071, 0, 0)
p.Content.DrawText(watermark, New PdfPoint(0, 0))
p.Content.RestoreGraphicsState()
End Using
Next p
existingDoc.Save("watermarked-document.pdf")
End Using
該範例展示了GemBox.Pdf在低層次PDF操作上的能力,展示了表單建立、圖形繪製和文件安全功能。 雖然該程式碼比IronPDF的HTML方法更加冗長,但它提供了對PDF的每一個方面的精細控制。
這些程式庫如何處理HTML到PDF的轉換?
HTML到PDF轉換的方法代表了IronPDF和GemBox.Pdf之間最顯著的差異之一。
IronPDF的HTML轉PDF方法
IronPDF自始便以HTML到PDF轉換為其主要焦點。 程式庫包含完整的Chrome渲染引擎,能夠像網頁瀏覽器一樣精確地處理HTML、CSS和JavaScript。 這意味著:
- 真實的瀏覽器渲染: 使用與Google Chrome相同的Blink引擎
- 完整的網頁標準: 全面支援CSS3、HTML5、flexbox、grid和現代JavaScript
- 動態內容: 在渲染前執行JavaScript,抓取AJAX內容和動態元素
- 響應式設計: 處理媒體查詢和響應式佈局
- 外部資源: 自動抓取來自URLs的圖像、樣式表和字體
GemBox.Pdf的HTML轉PDF方法
GemBox.Pdf 包含一個基於Chromium的引擎進行HTML到PDF轉換,支援HTML5、CSS3和JavaScript執行。 可以透過ConversionOptions API來自本地文件、實時URLs、HTML字串或流進行轉換。
IronPDF在此領域的區別在於其深入的Chrome V8整合和豐富的配置表面——包括自定義標題/頁腳、頁碼標記、列印背景控制、對JavaScript重量頁面的渲染延遲及其豐富的安全性/元資料選項,所有這些都通過單一整合的API公開。
現代CSS框架支持:一個關鍵差異
IronPDF的型態視覺化渲染對於現代CSS框架,如Bootstrap、Tailwind CSS和Foundation變得很明顯。 這些框架已成為現代Web應用的基石,並且在文档中正確呈現它們對於許多用例來說至關重要。
IronPDF:完全現代框架支持
IronPDF的Chrome渲染引擎提供對所有現代CSS框架的完整、原生支持:
- Bootstrap 5:完整Flexbox和CSS Grid支援以達到響應佈局
- Tailwind CSS: 完全支持utility-first CSS框架
- 現實範例: 精准呈現Bootstrap主頁和Bootstrap模板
- 現代CSS3功能: 動畫、變換、過渡、自訂屬性
- 響應式設計: 媒體查詢和基於視窗的佈局無縫運行
程式碼範例:Bootstrap表單到PDF
using IronPdf;
var renderer = new ChromePdfRenderer();
string bootstrapForm = @"
<!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 mt-5'>
<h1 class='mb-4'>Customer Registration</h1>
<form class='needs-validation'>
<div class='row g-3'>
<div class='col-md-6'>
<label class='form-label'>First Name</label>
<input type='text' class='form-control' value='John'>
</div>
<div class='col-md-6'>
<label class='form-label'>Last Name</label>
<input type='text' class='form-control' value='Smith'>
</div>
</div>
<div class='mt-4'>
<button class='btn btn-primary' type='submit'>Submit</button>
</div>
</form>
</div>
</body>
</html>";
var pdf = renderer.RenderHtmlAsPdf(bootstrapForm);
pdf.SaveAs("bootstrap-form.pdf");
using IronPdf;
var renderer = new ChromePdfRenderer();
string bootstrapForm = @"
<!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 mt-5'>
<h1 class='mb-4'>Customer Registration</h1>
<form class='needs-validation'>
<div class='row g-3'>
<div class='col-md-6'>
<label class='form-label'>First Name</label>
<input type='text' class='form-control' value='John'>
</div>
<div class='col-md-6'>
<label class='form-label'>Last Name</label>
<input type='text' class='form-control' value='Smith'>
</div>
</div>
<div class='mt-4'>
<button class='btn btn-primary' type='submit'>Submit</button>
</div>
</form>
</div>
</body>
</html>";
var pdf = renderer.RenderHtmlAsPdf(bootstrapForm);
pdf.SaveAs("bootstrap-form.pdf");
Imports IronPdf
Dim renderer As New ChromePdfRenderer()
Dim bootstrapForm 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 mt-5'>
<h1 class='mb-4'>Customer Registration</h1>
<form class='needs-validation'>
<div class='row g-3'>
<div class='col-md-6'>
<label class='form-label'>First Name</label>
<input type='text' class='form-control' value='John'>
</div>
<div class='col-md-6'>
<label class='form-label'>Last Name</label>
<input type='text' class='form-control' value='Smith'>
</div>
</div>
<div class='mt-4'>
<button class='btn btn-primary' type='submit'>Submit</button>
</div>
</form>
</div>
</body>
</html>"
Dim pdf = renderer.RenderHtmlAsPdf(bootstrapForm)
pdf.SaveAs("bootstrap-form.pdf")
GemBox.Pdf:基於Chromium的框架支持
GemBox.Pdf 使用一個Chromium引擎進行HTML到PDF轉換,提供HTML5和CSS3的基礎支持。使用標準瀏覽器渲染的現代CSS框架應與引擎層級相容。
IronPDF在此的優勢是其對Bootstrap,Tailwind CSS和其他框架的深入演示及測試支持,提供明確的範例、故障排除指南和配置選項(如視窗設置和渲染延遲),這些都是其核心API表面的一部分。 IronPDF的使用者從廣泛的社區資源和常見框架特定渲染場景的官方指導中受益。
現實考慮: 如果您的專案需要對Bootstrap或Tailwind佈局在PDF中呈現進行精細控制——包括自定義視窗大小、JavaScript驅動的內容或動態圖表渲染——IronPDF的豐富配置API和官方框架指南提供了一條更直接的路徑以達到生產級結果。
關於CSS框架相容性的更多資訊,請參見Bootstrap&Flexbox CSS指南。
哪個程式庫在不同的PDF任務中更優秀?
了解每個程式庫的強項有助於開發者為其特定需求選擇合適的工具。
IronPDF的優勢所在
IronPDF 適合於這些場景:
1. Web 應用程式 PDF 生成
非常適合SaaS應用、Web入口網站及任何需要將網頁內容轉換為PDF的系統。 Chrome渲染引擎確保複雜的Web佈局,包括使用Bootstrap、Tailwind CSS或自定框架的佈局,完美呈現。
2. 動態報告生成
當報告包含圖表(Chart.js、D3.js)、動態資料可視化或JavaScript呈現的內容時,IronPDF能精確捕捉所有內容。 這使得它成為商業情報儀表板和資料驅動應用的理想選擇。
3. 發票和文件模板
使用HTML/CSS模板用於發票、收據和商業文件允許設計師建立模板,而不需要學習PDF特定的API。可以快速使用熟悉的網頁技術進行更改。
4. 快速開發項目
簡單的API和基於HTML的方法顯著減少了開發時間。開發者可以在幾分鐘內建立一個複雜的PDF,而不是幾小時。
5. 跨平台部署
具有對Windows、Linux、macOS、Docker及雲平台的原生支援,IronPDF簡化了在不同環境中的部署。
GemBox.Pdf的優勢所在
GemBox.Pdf 在這些領域顯示出強項:
1. 低層次PDF操作
當需要精確控制PDF結構時,GemBox.Pdf的面向物件方法提供直接存取PDF元素、流和字典。
2. 頻繁使用表單的應用程式
對於廣泛使用PDF表單的應用程式,GemBox.Pdf提供全面的表單字段操作,包括程式式建立複雜的互動表單。
3. OCR需求
憑藉內建的OCR功能,GemBox.Pdf 可以從掃描文件中擷取文字而不需要額外的程式庫,使其適用於文件數位化項目。
4. 移動開發
對於需要PDF功能的移動應用,GemBox.Pdf對於Android和iOS平台提供原生支援,使其成為一個不錯的選擇。
5. 現有PDF的修改
在主要處理現有PDF而非生成新PDF時,GemBox.Pdf的提取、操作和修改工具非常適合這項工作。
安裝和設置如何比較?
兩個程式庫都能透過NuGet進行簡單的安裝,但複雜程度不同。
安裝 IronPDF
IronPDF安裝非常簡單:
Install-Package IronPdf
或藉由.NET CLI:
dotnet add package IronPdf
該套件包含所有所需的內容,包括Chrome渲染引擎。對於大多數用例,無需其他配置或依賴。
對於特定的部署場景,IronPDF提供:
IronPdf.Slim: 輕量型套件,在運行時下載平台特定組件IronPdf.Linux: 為Linux部署預先配置IronPdf.MacOs: 為macOS環境優化
安裝GemBox.Pdf
对于基本的PDF操作來說,GemBox.Pdf的安裝同樣簡單:
Install-Package GemBox.Pdf
不過,對於HTML到PDF轉換,您需要:
Install-Package GemBox.Document
兩個程式庫都需要配置授權金鑰:
// IronPDF
License.LicenseKey = "YOUR-LICENSE-KEY";
// GemBox.Pdf
ComponentInfo.SetLicense("YOUR-LICENSE-KEY");
// IronPDF
License.LicenseKey = "YOUR-LICENSE-KEY";
// GemBox.Pdf
ComponentInfo.SetLicense("YOUR-LICENSE-KEY");
' IronPDF
License.LicenseKey = "YOUR-LICENSE-KEY"
' GemBox.Pdf
ComponentInfo.SetLicense("YOUR-LICENSE-KEY")
授權和定價有什麼不同?
理解授權模式有助於確定每個解決方案的總擁有成本。
IronPDF 授權
IronPDF 提供透明的、分層授權(以2026年4月的價格計算):
-
Lite License: $999
- 1名開發人員
- 1個專案 - 1 年的支援和更新
-
Plus License: $1,499
- 3名開發人員
- 3個專案 - 1 年的支援和更新
- Professional License: $2,399
- 10名開發人員
- 10個專案 - 1 年的支援和更新
額外選項:
- 免版稅再分發:+$1,999
- 提供SaaS/OEM授權
- Iron Suite bundle:$2,998,包含10個產品
主要優勢:
- 30天退款保證
- 永久授權(一次性購買)
- 免費開發和測試
- 包含開發/預發布/生成的部署
GemBox.Pdf 授權
GemBox 提供每位開發者的授權(以2026年4月為準):
- Single Developer: $890
- 1名開發人員 - 無限專案 - 1 年的支援和更新 - 包含免版稅佈署
重要考量:
- 更新折扣40%(如在過期前更新可享60%)
- GemBox Bundle:$2,200,針對1名開發者(6個產品)
主要優勢:
- 30天退款保證
- 永久授權
- 包含無限佈署
- 不需要伺服器或OEM許可
常見場景的成本比較
| 場景 | IronPDF 成本 | GemBox.Pdf 成本 |
|---|---|---|
| 單一開發者,HTML轉PDF | $999 | $890 |
| 3位開發者,僅限PDF操作 | $1,499 | $4,450 (最多10位開發者) |
| 3位開發者,HTML轉PDF | $1,499 | $4,450 (最多10位開發者) |
| Enterprise (10 開發者),全功能 | $2,399 | $4,450 |
您應該選擇哪個程式庫?
在IronPDF和GemBox.Pdf之間的選擇取決於您的特定需求:
選擇IronPDF時:
- 豐富的HTML轉PDF配置是一個重點: IronPDF提供了標題/頁腳、JavaScript渲染延遲、視窗設置、PDF安全性和元資料的廣泛API——所有這些都在一個單一的綜合程式庫中
- 您需要深入文件化的框架整合: 官方指南和經過測試的範例,用于Bootstrap, Tailwind CSS, Chart.js和其他Web框架
- 快速開發很重要: 像
RenderHtmlAsPdf()這樣簡單的高級API方法可以縮短上市時間 - 需要跨平台部署: 優良的雲端和容器化環境支持,具有專用的Linux和macOS套件
- 預算是一個考量: 較低的進場成本和來自單一庫的廣泛功能集
選擇GemBox.Pdf時:
- 低層次的PDF控制是必需的: 對PDF物件和結構直接存取
- 需要移動平台支持: 原生Android和iOS相容性
- OCR是一個核心需求: 內建的OCR,無需其他依賴
- 您主要處理現有的PDF: 強大的操作和提取功能
- 無限佈署是重要的: 包含免版稅再分發,無需額外費用
考慮同時使用兩個程式庫時:
一些組織發現在應用的不同部分使用兩個程式庫具有價值:
- IronPDF用於報告生成和HTML轉PDF轉換
- GemBox.Pdf用於表單處理和PDF操作
入門指南選擇您選擇的程式庫
這兩個程式庫都提供免費試用以評估其功能:
試用IronPDF
- 安裝NuGet套件
- 開發不需要授權金鑰
- 試用模式下PDF上會出現水印
- 評估期間完全功能取用
試用GemBox.Pdf
- 安裝NuGet套件
- 使用
ComponentInfo.SetLicense("FREE-LIMITED-KEY") - 免費模式限制為2頁
- 升級以移除限制
視覺安裝指南
對於更偏愛於Visual Studio的圖形介面的開發者,這裡提供了一個逐步安裝兩個程式庫的指南:
建立新的ASP.NET專案
Visual Studio的新建專案對話框建立ASP.NET Web應用的基礎,以供PDF生成專案使用
選擇Web Form作為專案模板——適合於IronPDF和GemBox.Pdf的實現
透過NuGet安裝PDF程式庫
在方案總覽中右鍵單擊您的專案以存取NuGet套件管理器進行程式庫安裝
透過Visual Studio中的專案選單來存取NuGet套件管理器的替代方式
透過NuGet套件管理器安裝IronPDF——注意完整的功能描述和下載次數
替代安裝方法
IronPDF的網站提供直接的.dll下載,以應對NuGet安裝不合適的情境
結論
IronPDF和GemBox.Pdf都是為.NET開發者提供的優質PDF程式庫,各有各的優勢。 兩個程式庫都包括基於Chromium的HTML轉PDF轉換; IronPDF通過更豐富的配置API、更深入的網頁框架文件和在單一包中更多的功能集來區別自己。 GemBox.Pdf在低層次PDF操作、移動平台支援和內建OCR方面表現突出——使其非常適合於需要精確PDF結構控制的應用程式。
對於希望有廣泛文件支持和高度可配置的HTML到PDF工作流程的網頁開發者和團隊來說,IronPDF的統一API和廣泛的生態系統支持縮短了開發時間和複雜性。
然而,GemBox.Pdf依然是專業化場景中的可靠選擇,尤其是移動開發和專注於PDF表單處理或OCR需求的應用。
準備將您的HTML內容轉化為專業的PDF嗎? 開始使用IronPDF的免費試用版,並在您的.NET應用中體驗Chrome級別的渲染能力。 有了詳細的文件、廣泛的程式碼範例和響應迅速的支持,您將在幾分鐘內生成PDF,而不是幾小時。
[[i:(GemBox.Pdf和GemBox.Document是其各自擁有者的註冊商標。 本網站與GemBox.Pdf或GemBox.Document無關,未經其贊助或授權。 所有產品名稱、徽標和品牌均為其各自所有者的財產。 比較僅供資訊參考,並反映了撰寫時的公開可用資訊。
常見問題
如何在C#中將HTML轉換為PDF?
您可以使用IronPDF的RenderHtmlAsPdf方法將HTML字串轉換成PDF。也可以使用RenderHtmlFileAsPdf將HTML文件轉換為PDF。
我可以使用這些程式庫操作現有的PDF文件嗎?
是的,IronPDF和GemBox.Pdf都可以用來操作現有的PDF文件。IronPDF簡化了合併、分割和新增水印等常見任務。GemBox.Pdf則在PDF物件的控制上更為細緻,適合複雜的操作任務。
使用IronPDF進行HTML到PDF轉換有什麼優勢?
IronPDF的Chrome V8渲染引擎可提供卓越的HTML到PDF轉換質量,達到98%+的瀏覽器一致性。它支持現代CSS3、HTML5、JavaScript執行、網頁字體和響應式設計。
哪個程式庫對於小型開發團隊更具成本效益?
對於需要HTML到PDF轉換的3人開發團隊,IronPDF的Plus授權費用為$1,499,而GemBox則需要3個GemBox.Pdf授權和3個GemBox.Document授權,共計$5,340。IronPDF為團隊提供了更好的價值。
IronPDF適合用於大量PDF生成嗎?
是的,IronPDF提供了優異的性能,約125ms的HTML到PDF渲染時間,優化的async/await支持,以及低於10MB的高效記憶體使用。非常適合大量基於網頁的PDF生成。
IronPDF包含什麼型別的支持?
IronPDF提供24/5的工程支持,可直接存取開發團隊,通常24-48小時內回應,並附有全面的文件和程式碼範例。
我可以使用這些程式庫建立符合PDF/A的文件嗎?
是的,IronPDF可以通過簡單的調用如SaveAsPdfA()方法來生成符合PDF/A的文件,支持多個PDF/A版本。GemBox.Pdf可以讀取PDF/A文件並在修改時保持合規。
這些程式庫與現代.NET框架相容嗎?
是的,這兩個程式庫都支持現代.NET版本。IronPDF支持.NET Framework 4.6.2+、.NET Core 3.1+和.NET 5至10。GemBox.Pdf支持.NET Framework 3.5+、.NET Standard 2.0和.NET 6+。
哪個程式庫為雲端部署而優化?
IronPDF為雲端部署而優化,具有對Azure、AWS、Docker容器和無伺服器環境的特定支持。其基於HTML的方法自然適用於網頁應用,使其成為SaaS應用的更佳選擇。
IronPDF有免費版本供測試嗎?
IronPDF提供了免費的評估選項,允許無限制的開發和測試而無需授權金鑰,但輸出會有水印。這提供了充足的功能以評估產品後再購買。



