如何提取PDF文件中的頁面——逐步指南
在使用.NET應用程式時,PDF相關任務如轉換HTML-to-PDF、編輯PDF文件和PDF安全性經常是所需的,但開發者往往面臨不一致的輸出、有限的功能或複雜的整合過程等挑戰。 對於那些想要簡化這些任務的人,像IronPDF這樣的.NET PDF程式庫提供了一種超越基本HTML-to-PDF轉換的進階解決方案。
本比較涵蓋IronPDF和DinkToPdf在渲染能力、功能範圍、授權結構和定價方面的比較——並附有分隔它們的操作的程式碼範例。
了解PDF轉換需求
對於.NET開發者來說,HTML-to-PDF轉換通常是處理報告、發票和網頁內容等文件的要求。 然而,任務的複雜性可能會根據所轉換內容的不同而有顯著差異:
- 簡單頁面:靜態內容如文字和圖片通常很容易渲染。
- 動態頁面:複雜的佈局、媒體、腳本和互動元素需要更強健的解決方案。
除了基本的PDF生成之外,現代應用程式通常需要更先進的PDF功能:
- 數位簽名:確保文件的真實性和完整性。
- 加密:使用密碼保護來保護敏感資料。
- 浮水印:為PDF加入自定義品牌或安全標記。
- 內容操作:能夠從PDF中提取、編輯或新增內容。
對於大多數開發者來說,選擇一個不僅限於將HTML轉換為PDF的PDF程式庫是至關重要的。 一整套完整的PDF管理工具可以讓工作流程更加順暢和高效。
IronPDF提供了完整的功能範圍,可處理簡單和複雜的PDF任務。 DinkToPdf是簡單的HTML-to-PDF轉換的可靠選擇,但是許多團隊遇到阻力的地方在於進階的PDF管理——數位簽名、加密、浮水印和內容編輯在DinkToPdf的範圍之外。 在本節中,我們將比較每個程式庫如何應對這些挑戰,以幫助您確定哪一個解決方案最符合您的需求。
工具概覽
什麼是IronPDF?
IronPDF是一個為需要超越HTML-to-PDF轉換的開發者而建設的.NET PDF程式庫。 其API涵蓋了加密、數位簽名、浮水印、表單處理、文字或圖片提取——所有這些都在單個NuGet包中,適用於.NET Framework、.NET Core和.NET 5+。
HTML-to-PDF轉換由嵌入式Chromium引擎提供支援,具有完整的HTML5、CSS3和JavaScript支援。 商業授權包括詳細的文件說明,超過100個操作的程式碼範例,以及專用的支援團隊。
DinkToPdf是什麼?
另一方面,DinkToPdf是一個基於舊版Qt WebKit渲染引擎的開源HTML-to-PDF轉換程式庫,並且是wkhtmltopdf程式庫的.NET Core包裝層。 這是一個輕量級的解決方案,適合不需要高階功能的簡單、小型專案。 DinkToPdf可相對簡單地整合到.NET專案中,並且可以通過最少的設置從基本HTML和URL生成PDF。
雖然DinkToPdf程式庫是免費的替代方案,但其底層的Qt WebKit技術不再受到積極維護,並且具有已知的功能和安全限制。 由於Qt WebKit的開發在2016年停止,其渲染引擎未能完全支援現代HTML5、CSS3和JavaScript功能。 文件操控、加密和表單填充不在DinkToPdf目前的範圍內。 DinkToPdf專注於HTML渲染,因此需求延伸至這些領域的團隊通常需要額外新增程式庫或評估其他選擇。
以下是每個程式庫在本文中討論的不同能力中的並列快照:
| 功能 | IronPDF | DinkToPdf |
|---|---|---|
| 渲染引擎 | Chromium(當前) | Qt WebKit(凍結於2016) |
| HTML5 / CSS3 / JavaScript | 完整支援 | 部分支援 |
| Bootstrap 5和Flexbox | 支援 | 不支援 |
| 數位簽名 | 支援 | 不包含 |
| 加密和密碼 | 支援 | 不包含 |
| 浮水印 | 支援 | 不包含 |
| 表單填充 | 支援 | 不包含 |
| 授權 | 商業(免費試用) | LGPL |
| 專用支援 | 包含 | 僅限社群 |
評估IronPDF與DinkToPdf的團隊可以用免費30天試用測試此比較中的每個功能。
深入了解功能
IronPDF關鍵功能(附程式碼範例)
IronPDF作為單個NuGet包提供,處理HTML-to-PDF轉換、數位簽名、加密、浮水印、表單填充和內容提取——無需其他渲染程式庫。 它適用於.NET Framework、.NET Core和.NET 5+專案。 下面的程式碼範例展示了這些功能中的幾個實際運作的樣子。
HTML-to-PDF轉換
IronPDF的HTML-to-PDF轉換由其現代Chromium(Blink)渲染引擎提供支援,能完全支援HTML5、CSS3和JavaScript。 它轉換HTML頁面,同時確保原始的CSS樣式、媒體和JavaScript互動性得到保留。 這使其成為需要轉換動態內容並確保像素完美結果的開發者的絕佳選擇。
using IronPdf;
public class Program
{
public static void Main()
{
// Create a ChromePdfRenderer for rendering
ChromePdfRenderer renderer = new ChromePdfRenderer();
// Render an HTML file as a PDF
PdfDocument pdf = renderer.RenderHtmlFileAsPdf("example.html");
// Save the output PDF
pdf.SaveAs("example.pdf");
}
}
using IronPdf;
public class Program
{
public static void Main()
{
// Create a ChromePdfRenderer for rendering
ChromePdfRenderer renderer = new ChromePdfRenderer();
// Render an HTML file as a PDF
PdfDocument pdf = renderer.RenderHtmlFileAsPdf("example.html");
// Save the output PDF
pdf.SaveAs("example.pdf");
}
}
Imports IronPdf
Public Class Program
Public Shared Sub Main()
' Create a ChromePdfRenderer for rendering
Dim renderer As New ChromePdfRenderer()
' Render an HTML file as a PDF
Dim pdf As PdfDocument = renderer.RenderHtmlFileAsPdf("example.html")
' Save the output PDF
pdf.SaveAs("example.pdf")
End Sub
End Class
輸出:這個例子顯示了如何使用example.html)轉換為高質量PDF,保留所有樣式和腳本。 PDF保存為"example.pdf"。

URL轉PDF
IronPDF允許URL平順轉換為PDF,保持網頁的原始佈局和樣式。 這對於需要將整個網頁內容作為PDF截取的開發者來說,是完美的解決方案。
using IronPdf;
public class Program
{
public static void Main()
{
// Create a ChromePdfRenderer for rendering
ChromePdfRenderer renderer = new ChromePdfRenderer();
// Render a URL as a PDF
PdfDocument pdf = renderer.RenderUrlAsPdf("https://www.apple.com");
// Save the output PDF
pdf.SaveAs("UrlToPdf.pdf");
}
}
using IronPdf;
public class Program
{
public static void Main()
{
// Create a ChromePdfRenderer for rendering
ChromePdfRenderer renderer = new ChromePdfRenderer();
// Render a URL as a PDF
PdfDocument pdf = renderer.RenderUrlAsPdf("https://www.apple.com");
// Save the output PDF
pdf.SaveAs("UrlToPdf.pdf");
}
}
Imports IronPdf
Public Class Program
Public Shared Sub Main()
' Create a ChromePdfRenderer for rendering
Dim renderer As New ChromePdfRenderer()
' Render a URL as a PDF
Dim pdf As PdfDocument = renderer.RenderUrlAsPdf("https://www.apple.com")
' Save the output PDF
pdf.SaveAs("UrlToPdf.pdf")
End Sub
End Class
輸出:該範例演示了如何使用RenderUrlAsPdf()方法將網頁轉換為PDF文件。 此方法捕捉整個網頁並將其轉換為高質量的PDF文件。

PDF簽名
IronPDF允許開發者在PDF上應用數位簽名。 此功能對於確保文件的真實性和完整性至關重要。 開發者可以使用證書對PDF進行數位簽名,或者新增視覺簽名,如手寫簽名的圖像。
using IronPdf;
using IronPdf.Signing;
using System.Security.Cryptography.X509Certificates;
using IronSoftware.Drawing;
public class Program
{
public static void Main(string[] args)
{
// Load the certificate for signing
X509Certificate2 cert = new X509Certificate2("IronSoftware.pfx", "your-password", X509KeyStorageFlags.Exportable);
// Create a PdfSignature object using the certificate
var sig = new PdfSignature(cert);
// Specify a signature image
sig.SignatureImage = new PdfSignatureImage("IronPdf.png", 0, new Rectangle(150, 100, 350, 250));
// Sign and save the PDF document
sig.SignPdfFile("product_report.pdf");
}
}
using IronPdf;
using IronPdf.Signing;
using System.Security.Cryptography.X509Certificates;
using IronSoftware.Drawing;
public class Program
{
public static void Main(string[] args)
{
// Load the certificate for signing
X509Certificate2 cert = new X509Certificate2("IronSoftware.pfx", "your-password", X509KeyStorageFlags.Exportable);
// Create a PdfSignature object using the certificate
var sig = new PdfSignature(cert);
// Specify a signature image
sig.SignatureImage = new PdfSignatureImage("IronPdf.png", 0, new Rectangle(150, 100, 350, 250));
// Sign and save the PDF document
sig.SignPdfFile("product_report.pdf");
}
}
Imports IronPdf
Imports IronPdf.Signing
Imports System.Security.Cryptography.X509Certificates
Imports IronSoftware.Drawing
Public Class Program
Public Shared Sub Main(ByVal args() As String)
' Load the certificate for signing
Dim cert As New X509Certificate2("IronSoftware.pfx", "your-password", X509KeyStorageFlags.Exportable)
' Create a PdfSignature object using the certificate
Dim sig = New PdfSignature(cert)
' Specify a signature image
sig.SignatureImage = New PdfSignatureImage("IronPdf.png", 0, New Rectangle(150, 100, 350, 250))
' Sign and save the PDF document
sig.SignPdfFile("product_report.pdf")
End Sub
End Class
輸出:在此範例中,使用經認證的數位證書將看不見的數位簽名應用於PDF,確保其真實性,這對於處理重要或機密文件尤為重要。

自定義浮水印
IronPDF的能力擴展到了高階的PDF操作。 除了將HTML轉換為PDF外,它還允許開發者操作、提取和編輯PDF內容——新增浮水印、註釋和編輯PDF文件中的文字或圖片。 這裡我們演示瞭如何輕鬆地將自定義浮水印應用到您的PDF文件中。
using IronPdf;
public class Program
{
public static void Main()
{
// Define the watermark HTML content
string watermarkHtml = @"
<img src='https://ironsoftware.com/img/products/ironpdf-logo-text-dotnet.svg'>
<h1 style='Color: red'>CONFIDENTIAL</h1>";
// Load an existing PDF document
var pdf = PdfDocument.FromFile("ConfidentialDocument.pdf");
// Apply the watermark with specific settings
pdf.ApplyWatermark(watermarkHtml, opacity: 75, rotation: 45);
// Save the resultant PDF
pdf.SaveAs("ConfidentialDocumentWithWatermark.pdf");
}
}
using IronPdf;
public class Program
{
public static void Main()
{
// Define the watermark HTML content
string watermarkHtml = @"
<img src='https://ironsoftware.com/img/products/ironpdf-logo-text-dotnet.svg'>
<h1 style='Color: red'>CONFIDENTIAL</h1>";
// Load an existing PDF document
var pdf = PdfDocument.FromFile("ConfidentialDocument.pdf");
// Apply the watermark with specific settings
pdf.ApplyWatermark(watermarkHtml, opacity: 75, rotation: 45);
// Save the resultant PDF
pdf.SaveAs("ConfidentialDocumentWithWatermark.pdf");
}
}
Imports IronPdf
Public Class Program
Public Shared Sub Main()
' Define the watermark HTML content
Dim watermarkHtml As String = "
<img src='https://ironsoftware.com/img/products/ironpdf-logo-text-dotnet.svg'>
<h1 style='Color: red'>CONFIDENTIAL</h1>"
' Load an existing PDF document
Dim pdf = PdfDocument.FromFile("ConfidentialDocument.pdf")
' Apply the watermark with specific settings
pdf.ApplyWatermark(watermarkHtml, opacity:= 75, rotation:= 45)
' Save the resultant PDF
pdf.SaveAs("ConfidentialDocumentWithWatermark.pdf")
End Sub
End Class
輸出:範例展示了如何使用HTML和CSS應用自定義水印。 方法ApplyWatermark允許自定義旋轉、放置和透明度。

如果您想探索IronPDF提供的更多功能,請務必查看它的資訊豐富的功能頁面或其操作指南,這些指南包含每個功能的深入程式碼範例。
DinkToPdf關鍵功能(附程式碼範例)
DinkToPdf是一個輕量級的程式庫,使得HTML-to-PDF轉換成為可能,基於舊版Qt WebKit渲染引擎。需注意,Qt WebKit已不再積極維護,其渲染引擎未完全支援現代網頁標準。 這是一個簡單的開源解決方案,可從基本HTML和URL生成PDF。 高階的PDF編輯功能和現代網頁標準支援在其範圍之外,但它能夠有效地渲染簡單的結構化文件、發票和報告。 讓我們一起來探索一些其關鍵功能的實際範例。
HTML轉PDF
DinkToPdf允許開發者輕鬆地將HTML內容轉換為PDF,用於生成發票、報告和網頁的可列印版本。
using DinkToPdf;
using DinkToPdf.Contracts;
public class Program
{
public static void Main()
{
// Create a converter with the basic PDF tools
var converter = new BasicConverter(new PdfTools());
// Define the document's global and object settings
var doc = new HtmlToPdfDocument()
{
GlobalSettings = new GlobalSettings()
{
ColorMode = ColorMode.Color,
Orientation = Orientation.Portrait,
PaperSize = PaperKind.A4,
Out = "HtmlToPdf.pdf"
},
Objects =
{
new ObjectSettings()
{
PagesCount = true,
HtmlContent = "<h1>Hello, World!</h1><p>This is a PDF generated using DinkToPdf.</p>",
WebSettings = { DefaultEncoding = "utf-8" }
}
}
};
// Perform the conversion
converter.Convert(doc);
}
}
using DinkToPdf;
using DinkToPdf.Contracts;
public class Program
{
public static void Main()
{
// Create a converter with the basic PDF tools
var converter = new BasicConverter(new PdfTools());
// Define the document's global and object settings
var doc = new HtmlToPdfDocument()
{
GlobalSettings = new GlobalSettings()
{
ColorMode = ColorMode.Color,
Orientation = Orientation.Portrait,
PaperSize = PaperKind.A4,
Out = "HtmlToPdf.pdf"
},
Objects =
{
new ObjectSettings()
{
PagesCount = true,
HtmlContent = "<h1>Hello, World!</h1><p>This is a PDF generated using DinkToPdf.</p>",
WebSettings = { DefaultEncoding = "utf-8" }
}
}
};
// Perform the conversion
converter.Convert(doc);
}
}
Imports DinkToPdf
Imports DinkToPdf.Contracts
Public Class Program
Public Shared Sub Main()
' Create a converter with the basic PDF tools
Dim converter = New BasicConverter(New PdfTools())
' Define the document's global and object settings
Dim doc = New HtmlToPdfDocument() With {
.GlobalSettings = New GlobalSettings() With {
.ColorMode = ColorMode.Color,
.Orientation = Orientation.Portrait,
.PaperSize = PaperKind.A4,
.Out = "HtmlToPdf.pdf"
},
.Objects = {
New ObjectSettings() With {
.PagesCount = True, .HtmlContent = "<h1>Hello, World!</h1><p>This is a PDF generated using DinkToPdf.</p>", .WebSettings = { DefaultEncoding = "utf-8" }
}
}
}
' Perform the conversion
converter.Convert(doc)
End Sub
End Class
輸出:在此範例中,建立了一個BasicConverter實例來處理PDF轉換。 物件ObjectSettings中指定。

URL轉PDF
DinkToPdf還可以將現場網頁轉換為PDF格式,非常適合捕獲網頁報告、儀表板或任何動態內容。
// Similar to HTML-to-PDF with the Page property set to a URL
// (Example code is unavailable in the original content and left as a description)
// Similar to HTML-to-PDF with the Page property set to a URL
// (Example code is unavailable in the original content and left as a description)
' Similar to HTML-to-PDF with the Page property set to a URL
' (Example code is unavailable in the original content and left as a description)
輸出:此例子繼承了HTML-to-PDF轉換的相似方法,但改設Page屬性為逐小初始化一個URL。 Qt WebKit引擎捕捉頁面並將其轉換為PDF,雖然它可能對現代CSS3功能和JavaScript有局限性。

自定義頁面設置(邊距、標題和頁尾)
DinkToPdf提供了對頁面設定的精細控制,允許開發者設置自定義邊距、標題和頁尾,以達到專業文件格式。
using DinkToPdf;
using DinkToPdf.Contracts;
public class Program
{
public static void Main()
{
// Create a converter with the basic PDF tools
var converter = new BasicConverter(new PdfTools());
// Define the document's global and object settings
var doc = new HtmlToPdfDocument()
{
GlobalSettings = new GlobalSettings()
{
ColorMode = ColorMode.Color,
Orientation = Orientation.Portrait,
PaperSize = PaperKind.A4,
Out = "FormattedPdf.pdf",
Margins = new MarginSettings() { Top = 10, Bottom = 10, Left = 15, Right = 15 }
},
Objects =
{
new ObjectSettings()
{
HtmlContent = "<h1>Formatted PDF</h1><p>With custom margins and headers.</p>",
WebSettings = { DefaultEncoding = "utf-8" },
HeaderSettings = { Center = "Custom Header", FontSize = 10 },
FooterSettings = { Right = "Page [page] of [toPage]", FontSize = 10 }
}
}
};
// Perform the conversion
converter.Convert(doc);
}
}
using DinkToPdf;
using DinkToPdf.Contracts;
public class Program
{
public static void Main()
{
// Create a converter with the basic PDF tools
var converter = new BasicConverter(new PdfTools());
// Define the document's global and object settings
var doc = new HtmlToPdfDocument()
{
GlobalSettings = new GlobalSettings()
{
ColorMode = ColorMode.Color,
Orientation = Orientation.Portrait,
PaperSize = PaperKind.A4,
Out = "FormattedPdf.pdf",
Margins = new MarginSettings() { Top = 10, Bottom = 10, Left = 15, Right = 15 }
},
Objects =
{
new ObjectSettings()
{
HtmlContent = "<h1>Formatted PDF</h1><p>With custom margins and headers.</p>",
WebSettings = { DefaultEncoding = "utf-8" },
HeaderSettings = { Center = "Custom Header", FontSize = 10 },
FooterSettings = { Right = "Page [page] of [toPage]", FontSize = 10 }
}
}
};
// Perform the conversion
converter.Convert(doc);
}
}
Imports DinkToPdf
Imports DinkToPdf.Contracts
Public Class Program
Public Shared Sub Main()
' Create a converter with the basic PDF tools
Dim converter = New BasicConverter(New PdfTools())
' Define the document's global and object settings
Dim doc = New HtmlToPdfDocument() With {
.GlobalSettings = New GlobalSettings() With {
.ColorMode = ColorMode.Color,
.Orientation = Orientation.Portrait,
.PaperSize = PaperKind.A4,
.Out = "FormattedPdf.pdf",
.Margins = New MarginSettings() With {
.Top = 10,
.Bottom = 10,
.Left = 15,
.Right = 15
}
},
.Objects = {
New ObjectSettings() With {
.HtmlContent = "<h1>Formatted PDF</h1><p>With custom margins and headers.</p>", .WebSettings = { DefaultEncoding = "utf-8" },
.HeaderSettings = {
Center = "Custom Header",
FontSize = 10
},
.FooterSettings = {
Right = "Page [page] of [toPage]",
FontSize = 10
}
}
}
}
' Perform the conversion
converter.Convert(doc)
End Sub
End Class
輸出:此範例向PDF新增了自定義格式。 程式碼FooterSettings則定義了顯示頁碼的自定義標題和頁腳,以達到專業的佈局。

定價和授權
在為.NET專案選擇PDF程式庫時,授權和成本考量至關重要。 IronPDF和DinkToPdf遵循不同的授權模式,而正確的選擇取決於您的專案預算、需求和對支援的需求。
DinkToPdf授權和成本
DinkToPdf是一個開源程式庫,基於GNU較少一般公共許可證(LGPL)。 雖然這使其免費使用,將其部署在商業應用中的團隊應仔細閱讀LGPL的合規要求。
DinkToPdf授權
- LGPL許可證 - 專為開源和個人專案而免費。
- LGPL合規要求 - 在專有應用中使用的企業可能需要應付額外的授權義務。
- 無正式支援 - 由社區驅動,沒有專用的客戶服務。
- 額外的開發時間 - 團隊可能會花費額外的時間進行除錯和定制而沒有專用支援。
總結:雖然DinkToPdf沒有前期成本,但在商業專案中使用它的企業可能會面臨授權限制和額外的維護開銷。
IronPDF授權和成本
IronPDF遵循著為專業和企業用途設計的商業授權模式。 它提供了用於開發和評估的免費試用,但在全面生產使用時需要付費授權。
IronPDF授權
- 帶無開源碼限制的商業授權。
- 根據開發者或團隊授權的簡單定價。
- 包含所有主要功能——不需要為HTML-to-PDF、PDF安全性或其他核心工具支付額外成本。
- 專用的客戶支援和定期更新。
總結:IronPDF提供了一個具成本效益的全方位PDF解決方案,配備了專業支援,使其成為需要可靠、可擴展的PDF程式庫的團隊和企業的理想選擇。
對於正尋找長期解決方案並希望預測維護開銷的企業來說,IronPDF值得評估。 其結構化的授權、完整的功能集和持續的支援帶來了比DinkToPdf的聚焦範圍可能需要隨時間推移的整合和相容性工作的更高投資回報。
超越授權成本,總專案成本包括開發者工作在於克服Qt WebKit缺乏現代CSS支援的解決方案、為加密或數位簽名層到獨立程式庫、以及在專有程式碼庫中導航LGPL合規性。 對於評估多年度專案生命週期成本的團隊來說,這些整合和維護成本通常會超過開源和商業授權之間的差距。
現代CSS框架支持
IronPDF和DinkToPdf之間的一個關鍵區別是它們對Bootstrap、Tailwind CSS和Foundation這樣的現代CSS框架的支援。
IronPDF:全Bootstrap支持
IronPDF的Chromium渲染引擎提供了對現代CSS框架的完整支援:
- Bootstrap 5:完整Flexbox和CSS Grid支援以達到響應佈局
- 複雜布局: 像素完美地渲染Bootstrap主頁和Bootstrap範本
- 現代功能: CSS3動畫、轉換、過渡和媒體查詢
- CSS框架: Bootstrap, Tailwind CSS, Foundation, Bulma全都無縫運行
程式碼範例:渲染Bootstrap發票佈局
using IronPdf;
// Render a Bootstrap 5 invoice layout
var renderer = new ChromePdfRenderer();
// Example: Bootstrap invoice with table and flexbox
string bootstrapInvoice = @"
<!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'>
<div class='d-flex justify-content-between align-items-start mb-4'>
<div>
<h1>Invoice</h1>
<p class='text-muted'>#INV-2025-001</p>
</div>
<div class='text-end'>
<h4>Your Company</h4>
<p class='mb-0'>123 Business St</p>
<p>City, State 12345</p>
</div>
</div>
<table class='table table-bordered'>
<thead class='table-light'>
<tr>
<th>Description</th>
<th class='text-end'>Quantity</th>
<th class='text-end'>Price</th>
<th class='text-end'>Total</th>
</tr>
</thead>
<tbody>
<tr>
<td>Professional Services</td>
<td class='text-end'>10</td>
<td class='text-end'>$150.00</td>
<td class='text-end'>$1,500.00</td>
</tr>
<tr>
<td>Software License</td>
<td class='text-end'>1</td>
<td class='text-end'>$500.00</td>
<td class='text-end'>$500.00</td>
</tr>
</tbody>
<tfoot class='table-light fw-bold'>
<tr>
<td colspan='3' class='text-end'>Total:</td>
<td class='text-end'>$2,000.00</td>
</tr>
</tfoot>
</table>
</div>
</body>
</html>";
var pdf = renderer.RenderHtmlAsPdf(bootstrapInvoice);
pdf.SaveAs("bootstrap-invoice.pdf");
using IronPdf;
// Render a Bootstrap 5 invoice layout
var renderer = new ChromePdfRenderer();
// Example: Bootstrap invoice with table and flexbox
string bootstrapInvoice = @"
<!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'>
<div class='d-flex justify-content-between align-items-start mb-4'>
<div>
<h1>Invoice</h1>
<p class='text-muted'>#INV-2025-001</p>
</div>
<div class='text-end'>
<h4>Your Company</h4>
<p class='mb-0'>123 Business St</p>
<p>City, State 12345</p>
</div>
</div>
<table class='table table-bordered'>
<thead class='table-light'>
<tr>
<th>Description</th>
<th class='text-end'>Quantity</th>
<th class='text-end'>Price</th>
<th class='text-end'>Total</th>
</tr>
</thead>
<tbody>
<tr>
<td>Professional Services</td>
<td class='text-end'>10</td>
<td class='text-end'>$150.00</td>
<td class='text-end'>$1,500.00</td>
</tr>
<tr>
<td>Software License</td>
<td class='text-end'>1</td>
<td class='text-end'>$500.00</td>
<td class='text-end'>$500.00</td>
</tr>
</tbody>
<tfoot class='table-light fw-bold'>
<tr>
<td colspan='3' class='text-end'>Total:</td>
<td class='text-end'>$2,000.00</td>
</tr>
</tfoot>
</table>
</div>
</body>
</html>";
var pdf = renderer.RenderHtmlAsPdf(bootstrapInvoice);
pdf.SaveAs("bootstrap-invoice.pdf");
Imports IronPdf
' Render a Bootstrap 5 invoice layout
Dim renderer As New ChromePdfRenderer()
' Example: Bootstrap invoice with table and flexbox
Dim bootstrapInvoice 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'>
<div class='d-flex justify-content-between align-items-start mb-4'>
<div>
<h1>Invoice</h1>
<p class='text-muted'>#INV-2025-001</p>
</div>
<div class='text-end'>
<h4>Your Company</h4>
<p class='mb-0'>123 Business St</p>
<p>City, State 12345</p>
</div>
</div>
<table class='table table-bordered'>
<thead class='table-light'>
<tr>
<th>Description</th>
<th class='text-end'>Quantity</th>
<th class='text-end'>Price</th>
<th class='text-end'>Total</th>
</tr>
</thead>
<tbody>
<tr>
<td>Professional Services</td>
<td class='text-end'>10</td>
<td class='text-end'>$150.00</td>
<td class='text-end'>$1,500.00</td>
</tr>
<tr>
<td>Software License</td>
<td class='text-end'>1</td>
<td class='text-end'>$500.00</td>
<td class='text-end'>$500.00</td>
</tr>
</tbody>
<tfoot class='table-light fw-bold'>
<tr>
<td colspan='3' class='text-end'>Total:</td>
<td class='text-end'>$2,000.00</td>
</tr>
</tfoot>
</table>
</div>
</body>
</html>"
Dim pdf = renderer.RenderHtmlAsPdf(bootstrapInvoice)
pdf.SaveAs("bootstrap-invoice.pdf")
上述程式碼完美地由IronPDF渲染,保留了所有Bootstrap樣式,包括Flexbox佈局、表格樣式和實用類。
DinkToPdf:Bootstrap相容性限制
DinkToPdf依賴於wkhtmltopdf及其基本Qt WebKit引擎,其渲染管道早於幾個現代CSS規範:
- 無Flexbox支援:Bootstrap 4+大量依賴於Flexbox,而Qt WebKit的引擎無法完全支援
- 不包含CSS Grid:現代的網格佈局將無法正確呈現
- 引擎凍結於2016:Qt WebKit的最後更新早於許多當前CSS3功能
- 安全考慮:Qt WebKit有已知的安全漏洞且不再維護
- 需要工作區:開發者通常需要使用舊版Bootstrap(Bootstrap 3或更早)或實現基於表格的替代方案
有關CSS框架支援和Flexbox/Bootstrap渲染問題的故障排除的更多細節,參見Bootstrap & Flexbox CSS指導。
您應該選擇哪個程式庫?
為您的.NET專案選擇適當的程式庫取決於易用性、功能和授權等因素。 兩者IronPDF和DinkToPdf都提供HTML到PDF的功能,但它們服務於不同的需求。 DinkToPdf是免費和開源的,這使得它成為可觸及的起始點,儘管團隊可能會在授權限制、缺乏正式支援和Qt WebKit引擎的狹窄表面對現代網頁標準方面遇到阻力。 IronPDF提供了一個功能更全面、專業級的解決方案,具有現代Chromium渲染引擎、商業授權和專用支援。
IronPDFvs. DinkToPdf:關鍵要點
為什麼選擇IronPDF?
- 易用性 - 簡單的API,最小化開發時間。
- 高度自定義選項 - 生成完全自定義以滿足您需求的PDF文件。
- 全面的功能集 - 包含HTML-to-PDF,URL-to-PDF,浮水印,加密和數位簽名。
- 現代渲染引擎 - 使用嵌入式Chromium引擎,具有完整HTML5、CSS3和JavaScript支援,以達到高保真輸出。
- 商業授權及支援 - 永久授權,附有專用客戶幫助。
DinkToPdf的取捨
- 無正式支援 - 依賴於社區幫助,這可能不一致。
- 有限更新 - 依賴於義工的貢獻來維護。
- LGPL合規性義務 - LGPL授權引入的要求可能不符合每個商業部署模型。
最後想法
對於需要可靠、全力支援PDF解決方案的團隊來說,IronPDF值得認真考慮。 其開發者友好API、全面的功能集以及簡單的商業授權使其成為任何規模的.NET專案的理想之選。
今日試用IronPDF——下載免費試用並自行測試此比較中展示的每個功能。
常見問題
如何在C#中將HTML轉換為PDF?
您可以使用IronPDF的RenderHtmlAsPdf方法將HTML字串轉換成PDF。也可以使用RenderHtmlFileAsPdf將HTML文件轉換為PDF。
使用IronPDF與DinkToPdf相比的主要優勢是什麼?
IronPDF提供了全面的功能集,超越基本的HTML到PDF轉換,包括加密、數位簽名、加水印和表單處理。它還提供專屬的客戶支持和簡單的商業授權模式。
我應該考慮IronPDF和DinkToPdf之間的授權差異嗎?
DinkToPdf在GNU較寬鬆通用公共授權(LGPL)下提供,對於開源項目是免費的,但可能對商業使用有所限制。IronPDF遵循商業授權模式,沒有開源限制,適合專業和企業使用。
IronPDF能處理具有複雜佈局的動態網頁嗎?
是的,IronPDF可以將具有複雜佈局、媒體、腳本和互動元素的動態頁面進行轉換,同時保留CSS樣式和JavaScript的互動性。
IronPDF支持向PDF新增數位簽名嗎?
是的,IronPDF允許開發者使用證書對PDF應用數位簽名,確保文件的真實性和完整性。
DinkToPdf有哪些限制?
DinkToPdf缺少許多複雜PDF工作流程所需的高級功能,例如文件操作、加密或表單填寫。它還依賴社區支持,這可能不一致。
IronPDF如何確保高質量的PDF渲染?
IronPDF使用強大的渲染引擎,確保原始CSS樣式、媒體和JavaScript互動性得以保留,使其適合於動態內容轉換並確保像素級的結果。
DinkToPdf能將URL轉換為PDF嗎?
是的,DinkToPdf可以將實時網頁轉換為PDF格式,捕捉整個網頁,同時保留樣式和格式。
IronPDF提供什麼樣的支持?
IronPDF提供專屬的客戶支持和定期更新,這是其商業授權模式的一部分。
IronPDF為什麼被認為對企業具有成本效益?
IronPDF提供一個具成本效益的綜合PDF解決方案,附帶專業支持,使其非常適合需要可靠且可擴展PDF程式庫的企業,沒有與開源替代方案相關的隱藏成本。



