IronPDF & ComPDFKit之間的比較
IronPDF 在 C# PDF 生成方面優於 ComPDFKit,具備原生 Chromium 基礎的 HTML 渲染、完整的 Bootstrap 支援、詳盡的文件,以及卓越的 .NET Framework 整合能力;而ComPDFKit則需透過外部 API 呼叫進行 HTML 轉換,且缺乏對進階 CSS 框架的相容性。
PDF是便攜式文件格式的縮寫,是 Adobe 為確保文件共享的統一性而創建的一種文件類型。 此格式能在各種裝置和作業系統上,一致地維持版面配置、文字及圖片的呈現。 PDF 具備安全性、互動功能及檔案體積小等優勢,使其成為分發文件且不被篡改內容的理想選擇。
對於使用 C# 的開發人員而言,PDF 函式庫提供了處理 PDF 檔案的解決方案。 這些函式庫可實現文件建立、內容修改,以及文字與圖片的擷取。 它們支援表單處理、數位簽章及跨平台相容性等功能。 這些函式庫專為提升效能而設計,可實現高效的 PDF 處理。
本文比較了兩款 C# PDF 函式庫:IronPDF 與 ComPDFKit。 此比較涵蓋功能、運作方式、程式碼範例及授權條款。 透過評估這些方面,開發人員可判斷哪個函式庫最適合其 PDF 相關專案。
快速比較概述
在深入分析之前,以下是各項關鍵功能的完整比較:
| 特點 | IronPDF | ComPDFKit |
|---|---|---|
| HTML至PDF | 原生 Chromium 引擎 | 需使用外部 API |
| Bootstrap 支援 | 完整支援 CSS3/Flexbox | 對 CSS 框架的支援有限 |
| 安裝 | 單一 NuGet 套件 | 需要多個套件 |
| 說明文件 | 內容詳盡,附有 500 多個範例 | 基本文件 |
| <強>支援</強 | 24/5 專屬工程支援 | 標準電子郵件支援 |
| 定價模式 | 永久許可,起價 749 美元 | 按字數計費 |
| 跨平台 | Windows、Linux、macOS、Docker、Azure | Windows, Linux, macOS |
| 表現 | 最佳化的非同步/多執行緒 | 標準同步處理 |
| Enterprise級功能 | PDF/A、PDF/UA、HSM 簽名 | 基本 PDF/A 支援 |
| 學習曲線 | 極簡直直觀的 API | 中等至複雜的 API 結構 |
- PDF 檢視:ComPDFKit 提供強大的 PDF 檢視器,讓使用者能以高保真度檢視 PDF 文件。 檢視器支援流暢的捲動、縮放和導航,以確保順暢的使用者體驗。
- 註解:此函式庫包含可順暢整合 PDF 註解的工具。 使用者可以反白文字、新增註解,以及建立各種類型的註解,這些都是協同工作流程中不可或缺的功能。
- 表單處理:此函式庫提供對互動式表單的廣泛支援。 開發人員可以從 PDF 表單中建立、填寫及擷取資料,因此非常適合需要表單處理的應用程式。
- PDF 編輯:ComPDFKit 提供廣泛的 PDF 編輯功能,包括修改 PDF 檔案中的文字、圖片及其他內容。 此功能對於需要更新或自訂現有 PDF 文件的應用程式非常有用。
- 轉換:此函式庫支援將 PDF 檔案與 WORD、Excel、PowerPoint 及圖像等各種格式相互轉換。 這種靈活性對於需要轉換 PDF 內容作不同用途的應用程式來說至關重要。
- 安全性:ComPDFKit 具備強大的安全性功能,例如加密與權限管理。 開發人員可保護 PDF 文件的安全,以防止未經授權存取敏感資訊。
- 光學字元辨識 (OCR):此函式庫具備 OCR 功能,可將掃描的文件轉換為可編輯且可搜尋的 PDF 檔案。 此功能對於將紙本文件數位化並使其能以電子方式存取是非常重要的。
ComPDFKit 主頁展示了其面向開發人員的完整 PDF SDK 解決方案,其中包含註釋功能的螢幕截圖和程式碼範例,並演示了 PDF 操作功能。
ComPDFKit PDF SDK 是一款可靠的 C# PDF SDK,讓開發人員能夠將完整的 PDF 功能整合至其應用程式中。 本程式庫支援以程式化方式處理 PDF 文件所需的各種 PDF 功能。 本手冊設計可在各種環境下使用,包括網頁、桌上型電腦和行動平台,因此是開發人員進行跨平台專案的多用途工具。 範例解決方案包含多個功能,開發人員可自行選擇並進行測試。
ComPDFKit提供哪些主要功能?
核心功能:
- PDF 檢視:提供具備流暢捲動、Zoom 及導覽功能的高效檢視器
- 註解:包含用於標示文字、添加註解以及建立各種註解類型的工具
- 表單處理:提供建立、填寫及從互動式 PDF 表單中擷取資料的功能
- PDF 編輯:允許修改現有 PDF 文件中的文字、圖片及其他內容
-轉換:支援將 PDF 檔案轉換為 Word、Excel、
PowerPoint和圖片格式 - 安全性:包含加密與權限管理功能,以保護敏感資訊
- 光學字元辨識 (OCR):將掃描的文件轉換為可編輯且可搜尋的 PDF 檔案
為何考慮採用ComPDFKit的架構?
- HTML 轉 PDF:IronPDF 擅長將 HTML、CSS 和 JavaScript 內容轉換為高品質的 PDF 文件。 此功能支援 HTML 字串轉換為 PDF、URL、ASPX 網頁表格和 MVC 視圖,使其成為各種網頁內容的彈性解決方案。
- PDF 編輯:此函式庫提供廣泛的編輯功能,包括新增、複製及刪除頁面、合併與分割 PDF 檔案,以及操作文字與圖片。 開發人員也可以在 PDF 文件中加入頁眉、頁腳、水印和數位簽章。
- 表單處理:IronPDF 支援智慧表單建立,並可透過程式化方式填寫 PDF 表單。 此功能對於需要動態表單生成以及從使用者提交的表單中擷取資料的應用程式而言是不可或缺的。
- 安全性功能:IronPDF 提供強大的安全性選項,例如設定密碼與權限、加密文件,以及添加數位簽章。 這些功能可確保 PDF 文件中的敏感資訊不會受到未經授權的存取。
- OCR 與資料擷取:此函式庫具備光學字元辨識 (OCR) 功能,可將掃描文件轉換為可編輯且可搜尋的 PDF 檔案。 此外,IronPDF 可以從現有 PDF 中萃取文字、圖片和其他資料,方便內容重用和分析。
- 圖片轉換:IronPDF 支援將各種圖片格式(包括 JPG、PNG、GIF、BMP 和 SVG)轉換為 PDF 文件。 它還提供將 PDF 頁面呈現為影像的功能,這對需要可視化預覽 PDF 內容的應用程式非常有用。
- 跨平台相容性:IronPDF 相容於多個 .NET 平台,包括 .NET Core、.NET Framework 及 .NET Standard。 它支援 Windows、Linux、macOS 和 Azure 上的部署,使其成為在不同環境中工作的開發人員的多用途選擇。
- 效能優化:此函式庫專為高效能而設計,支援多執行緒與非同步操作。 這可確保 PDF 處理任務能有效率地執行,即使是在高工作量的應用程式中。
- 完整的文件與支援:IronPDF 提供詳盡的文件與大量程式碼範例,讓開發人員能輕鬆上手並實作其功能。 此外,它還提供技術支援,協助解決開發過程中可能出現的任何問題。
對於需要可靠註解功能的 Enterprise 級應用程式,ComPDFKit 提供了基礎功能。 進階表單建立功能可能需要額外的程式設計工作量。 雖然該工具可滿足 OCR 任務的基本需求,但若開發者需要進階的文字辨識功能,建議評估其他替代方案(如 IronOCR),以獲得更高的辨識準確度。
ComPDFKit有哪些限制?
儘管功能完備,ComPDFKit 在 Enterprise 級開發中仍存在若干限制:
- HTML 渲染:不支援原生 HTML 轉 PDF 功能 — 需透過外部 API 呼叫實現
- CSS 支援:對現代 CSS 框架的相容性有限
- 效能:缺乏內建的異步/多執行緒優化
- 文件說明:僅包含基礎範例,不包含完整的疑難排解指南
- 整合複雜度:需搭配多個套件才能實現完整功能
什麼是IronPDF函式庫?
IronPDF 主頁展示了 C# PDF 庫介面,並提供了 HTML 到 PDF 轉換的程式碼範例,重點介紹了超過 1000 萬次的下載量以及財富 500 強企業中的企業級應用。
IronPDF 是適用於 .NET 的多功能 PDF 函式庫,可讓開發人員使用 C# 建立、編輯和管理 PDF 文件。 它透過簡化的 API 提供完整的 PDF 功能。該函式庫擅長透過渲染 HTML、CSS、JavaScript 及各種圖像格式來生成 PDF。 這使其成為開發人員將可靠的 PDF 功能整合至 .NET 應用程式時的理想工具。
IronPDF提供哪些主要功能?
進階功能:
- HTML 轉 PDF:利用 Chrome 渲染引擎,將 HTML、CSS 和 JavaScript 轉換為高品質的 PDF 檔案
- PDF 編輯:完整的頁面操作功能,包括合併、分割及內容修改
- 表單處理:完整支援建立及透過程式碼填寫 PDF 表單
- 安全性功能:具備 256 位元加密技術的進階 PDF 權限與密碼設定
- OCR 與資料擷取:內建具備解析功能的文字與圖像擷取功能
- 圖片轉換:原生支援圖片轉 PDF 及 PDF 點陣化
- 跨平台相容性:針對 Windows、Linux、macOS 及 Azure 進行了最佳化
- 效能優化:針對高效能情境提供原生非同步/多執行緒支援
- Enterprise 功能:符合 PDF/A 標準、數位簽章及 HSM 整合
為何選擇IronPDF作為生產系統的解決方案?
IronPDF 的架構優先考量生產環境的效能與可靠性:
- Chromium 渲染引擎:確保 HTML 轉換達到像素級精準度
- 記憶體管理:針對處理大型文件進行了優化
- 執行緒安全性:專為網頁應用程式的並行操作而設計
- 完整文件:超過 500 個程式碼範例與教學指南 -企業支援:針對複雜場景的專屬工程支持
是什麼讓IronPDF具備 Enterprise 級應用能力?
IronPDF 憑藉其專注於生產環境的功能脫穎而出:
如何建立新的 Visual Studio 專案?
在探索程式碼範例之前,開發人員應先建立一個新的 Visual Studio 專案。 本指南概述了在 Visual Studio 中設定 C# 主控台應用程式的步驟。
為什麼我需要安裝 Visual Studio?
Visual Studio 為 C# 專案提供最佳的整合開發環境 (IDE)。 請從 Visual Studio 下載頁面取得。 該 IDE 提供整合偵錯、IntelliSense 和套件管理,這對於 PDF 開發至關重要。
哪種專案配置最為理想?
安裝完成後,請開啟 Visual Studio。 請登入,或在使用 Visual Studio Community 時選擇不登入繼續。 請遵循以下設定步驟:
-
點擊"建立新專案",或前往"檔案">"新增">"專案"。
Visual Studio IDE 顯示"檔案"功能表已打開,其中包含建立新專案、開啟檔案和管理儲存庫的選項,其中"新專案"選項已被反白顯示。
-
搜尋"Console app",並從搜尋結果中選取"Console Application"。
Visual Studio 的"建立新專案"對話方塊顯示了控制台應用程式範本選擇,其中突出顯示了 C#、Linux、macOS、Windows 和 Console 標籤,以便進行跨平台開發。
- 開啟 NuGet 套件管理員:在"解決方案總覽"中,右鍵點擊"參考項目",然後選擇"管理 NuGet 套件"。
- 搜尋與安裝:在 NuGet 套件管理員中搜尋"ComPDFKit"。 選擇適當的套件 (例如,ComPDFKit.NetFramework 或 ComPDFKit.Conversion.NetFramework),然後按一下 "安裝"。
什麼是必要的專案設定?
- 驗證安裝:確認該套件已出現在"解決方案總覽"的"參考項目"中。
- 目標平台:處理大型文件時請設定為 x64
- 輸出類型:測試用主控台應用程式、生產環境用類別庫
- 框架版本:建議使用 .NET 6+ 以獲得最佳效能
- NuGet 套件管理:啟用套件還原功能以進行依賴項管理
- 下載套件:從ComPDFKit官方網站取得 ComPDFKit.NetFramework.nupkg 檔案。
- 設定 NuGet 來源:在專案目錄中建立或編輯 nuget.config 檔案,以加入本地套件的路徑。
將IronPDF整合至專案中可透過多種方式實現。 如需完整的安裝概覽,請參閱官方文件。 此函式庫支援多種安裝方式,可配合不同的開發工作流程。
-
安裝本機套件:在 Visual Studio 中重新開啟您的解決方案,前往"管理 NuGet 套件",並選取您的本機套件來源。 從本機安裝ComPDFKit套件。
-
Visual Studio NuGet 套件管理員:在解決方案中右鍵點擊"依賴項",然後選擇"管理 NuGet 套件"。在"瀏覽"索引標籤中,搜尋"IronPDF"並安裝最新版本。 如需進階的 NuGet 安裝選項,請參閱詳細指南。
- 取得授權:請聯絡ComPDFKit團隊以獲取試用授權或完整授權。
-
在程式碼中套用授權條款:
-
套件管理員主控台:透過"工具">"NuGet 套件管理員">"套件管理員主控台"使用 NuGet 套件管理員主控台。 執行以下指令:
_CODEBLOCK0
這可透過命令列介面快速安裝函式庫。

-
直接下載方法:請造訪 IronPDF NuGet 套件頁面。 下載套件檔案,雙擊以將其加入專案,然後重新載入解決方案。
- 手動安裝:直接下載最新版本的 IronPDF。 請依照提供的說明進行 Visual Studio 手動整合。 有關 Windows 專用的安裝說明,請參閱 Windows 安裝程式指南。
為何選擇特定的安裝方式?
不同的安裝方式適用於各種情境:
- NuGet 套件管理員:最適合具備網路連線能力的 Visual Studio 使用者
- 套件管理主控台:非常適合用於腳本化部署及 CI/CD 管道
- 直接下載:適用於離線開發環境
- 手動安裝:適用於自訂部署設定
這些方法能將IronPDF有效整合至 .NET 專案中。 如需快速入門說明,請參閱《入門指南》。各平台專用指南涵蓋 F# 整合與 VB.NET 使用方式。
如何安裝ComPDFKitC#?
將ComPDFKit加入專案主要有兩種方法:NuGet 套件管理員或本地套件安裝。 相較於IronPDF的單一套件方案,其安裝流程需要更多步驟。
何時該使用 NuGet 套件管理員?
- 開啟 NuGet 套件管理員:在"解決方案總覽"中右鍵點擊"參考項目",然後選擇"管理 NuGet 套件"。
- 搜尋與安裝:在套件管理員中搜尋"ComPDFKit"。 選擇適當的軟體包(ComPDFKit.
NetFramework或 ComPDFKit.Conversion.NetFramework),然後按一下"安裝"。
3.驗證安裝:確保套件出現在解決方案總管的"參考資料"下。 若要實現完整功能,可能需要安裝多個套件。
何時該使用本地化套件?
在地化Suite安裝適用於受限環境:
1.下載軟體包:從ComPDFKit官方網站取得 ComPDFKit.NetFramework.nupkg。
2.配置 NuGet 來源:在專案目錄中建立或編輯 nuget.config,以包含本機套件路徑。
___CODEBLOCK_1___
- 安裝本機套件:重新開啟解決方案,導航至"管理 NuGet 套件",選取本機套件來源,並安裝 ComPDFKit。
如何套用我的授權金鑰?
各函式庫的授權實作方式存在顯著差異:
- 取得授權:請聯絡ComPDFKit申請試用授權或完整授權。
-
在程式碼中套用授權:
_CODEBLOCK2
請新增此方法以驗證授權。 關於IronPDF更簡易的授權實作方式,請參閱授權金鑰文件。IronPDF只需設定
License.LicenseKey屬性,即可簡化許可流程。
如何將 HTML 轉換為 PDF?
將 HTML 轉換為 PDF 是從網頁內容生成報告、發票或文件時的一項常見需求。IronPDF和ComPDFKit皆提供解決方案,但兩者的實現方式有顯著差異。IronPDF提供原生轉換功能,而ComPDFKit則需要透過外部 API 進行呼叫。
IronPDF如何處理 HTML 轉 PDF 的轉換?
IronPDF 採用基於 Chrome 的渲染引擎,以確保輸出品質優良。 此流程能將 HTML、CSS 和 JavaScript 精確轉譯為 PDF 格式。 此函式庫支援 HTML 字串、HTML 檔案及 URL。
基本的 HTML 字串轉 PDF 範例:
using IronPdf;
using System;
class Program
{
static void Main()
{
// Define your HTML string
string htmlString = @"
<h1>Hello, IronPDF!</h1>
<p>This is a simple PDF created from an HTML string.</p>";
var renderer = new ChromePdfRenderer();
// Convert the HTML string to a PDF document
PdfDocument pdf = renderer.RenderHtmlAsPdf(htmlString);
// Save the PDF document to a file
string outputPath = "sample.pdf";
pdf.SaveAs(outputPath);
Console.WriteLine($"PDF created successfully and saved to {outputPath}");
}
}
using IronPdf;
using System;
class Program
{
static void Main()
{
// Define your HTML string
string htmlString = @"
<h1>Hello, IronPDF!</h1>
<p>This is a simple PDF created from an HTML string.</p>";
var renderer = new ChromePdfRenderer();
// Convert the HTML string to a PDF document
PdfDocument pdf = renderer.RenderHtmlAsPdf(htmlString);
// Save the PDF document to a file
string outputPath = "sample.pdf";
pdf.SaveAs(outputPath);
Console.WriteLine($"PDF created successfully and saved to {outputPath}");
}
}
Imports IronPdf
Imports System
Friend Class Program
Shared Sub Main()
' Define your HTML string
Dim htmlString As String = "
<h1>Hello, IronPDF!</h1>
<p>This is a simple PDF created from an HTML string.</p>"
Dim renderer = New ChromePdfRenderer()
' Convert the HTML string to a PDF document
Dim pdf As PdfDocument = renderer.RenderHtmlAsPdf(htmlString)
' Save the PDF document to a file
Dim outputPath As String = "sample.pdf"
pdf.SaveAs(outputPath)
Console.WriteLine($"PDF created successfully and saved to {outputPath}")
End Sub
End Class
IronPDF 輸出顯示一個簡單的 PDF 文件,標題為"Hello, IronPDF!",並附有描述性文本,演示了基本的 HTML 到 PDF 轉換功能。
IronPDF 亦可直接轉換 HTML 檔案,並支援嵌入 CSS 與 JavaScript:
using IronPdf;
using System;
class Program
{
static void Main()
{
var renderer = new ChromePdfRenderer();
// Convert the HTML file to a PDF document
PdfDocument pdf = renderer.RenderHtmlFileAsPdf("index.html");
// Save the PDF document to a file
string outputPath = "HTML File.pdf";
pdf.SaveAs(outputPath);
Console.WriteLine($"PDF created successfully and saved to {outputPath}");
}
}
using IronPdf;
using System;
class Program
{
static void Main()
{
var renderer = new ChromePdfRenderer();
// Convert the HTML file to a PDF document
PdfDocument pdf = renderer.RenderHtmlFileAsPdf("index.html");
// Save the PDF document to a file
string outputPath = "HTML File.pdf";
pdf.SaveAs(outputPath);
Console.WriteLine($"PDF created successfully and saved to {outputPath}");
}
}
Imports IronPdf
Imports System
Friend Class Program
Shared Sub Main()
Dim renderer = New ChromePdfRenderer()
' Convert the HTML file to a PDF document
Dim pdf As PdfDocument = renderer.RenderHtmlFileAsPdf("index.html")
' Save the PDF document to a file
Dim outputPath As String = "HTML File.pdf"
pdf.SaveAs(outputPath)
Console.WriteLine($"PDF created successfully and saved to {outputPath}")
End Sub
End Class
!範例發票 #123 顯示網站設計服務總計 385 美元,以 PDF 文件形式呈現,專業格式和佈局從 HTML 來源保留。
IronPDF支援哪些進階 HTML 功能?
IronPDF 的 Chromium 引擎可處理複雜的網頁技術:
- JavaScript 渲染:全面支援 JavaScript 執行,包含各種框架
- CSS3 支援:完整的響應式 CSS 渲染
- 資產管理:資源載入的基礎 URL 與資產編碼
- 自訂版面配置:自訂紙張尺寸與頁面方向
- 進階格式設定:分頁控制與自訂邊距
- 國際化支援:UTF-8 及多國語言
- 效能選項:WaitFor 延遲(用於動態內容)
ComPDFKit如何處理 HTML 轉 PDF 的轉換?
- 傳送 HTML 內容:建立一個包含您的 HTML 內容的 HTTP POST 請求,並傳送至ComPDFKitAPI 端點。
- 接收 PDF 輸出:API 會處理 HTML 內容,並回傳生成的 PDF 檔案。
使用ComPDFKit的 HTML 轉 PDF API:
- 傳送 HTML 內容:建立包含 HTML 內容的 HTTP POST 請求
- 接收 PDF 輸出:API 處理內容並回傳生成的 PDF
C# 語言中 API 請求的範例結構:
using System;
using System.Net.Http;
using System.Threading.Tasks;
public class HtmlToPdfExample
{
public static async Task ConvertHtmlToPdfAsync()
{
using (var client = new HttpClient())
{
var content = new StringContent("<h1>Hello World</h1>");
var response = await client.PostAsync("___PROTECTED_URL_137___", content);
var pdfBytes = await response.Content.ReadAsByteArrayAsync();
System.IO.File.WriteAllBytes("output.pdf", pdfBytes);
}
}
}
using System;
using System.Net.Http;
using System.Threading.Tasks;
public class HtmlToPdfExample
{
public static async Task ConvertHtmlToPdfAsync()
{
using (var client = new HttpClient())
{
var content = new StringContent("<h1>Hello World</h1>");
var response = await client.PostAsync("___PROTECTED_URL_137___", content);
var pdfBytes = await response.Content.ReadAsByteArrayAsync();
System.IO.File.WriteAllBytes("output.pdf", pdfBytes);
}
}
}
Imports System
Imports System.Net.Http
Imports System.Threading.Tasks
Public Class HtmlToPdfExample
Public Shared Async Function ConvertHtmlToPdfAsync() As Task
Using client As New HttpClient()
Dim content As New StringContent("<h1>Hello World</h1>")
Dim response As HttpResponseMessage = Await client.PostAsync("___PROTECTED_URL_137___", content)
Dim pdfBytes As Byte() = Await response.Content.ReadAsByteArrayAsync()
System.IO.File.WriteAllBytes("output.pdf", pdfBytes)
End Using
End Function
End Class
基於 API 的轉換有哪些限制?
ComPDFKit 的 API 設計帶來了幾項挑戰:
- 網路依賴性:基本操作需具備網際網路連線
- 延遲問題:API 往返會增加處理時間
- 控制受限:無法自訂渲染引擎的行為
- 安全性考量:傳輸至外部伺服器的敏感資料
- 速率限制:API 配額可能會限制大量處理
- 文件不足:C# 實作範例有限
Bootstrap CSS 是否適用於 PDF 生成?
現代的電子商務與商業應用程式廣泛採用 Bootstrap,以實現一致的 UI 設計。 在將發票、收據和報告產生為 PDF 檔案時,維持 Bootstrap 樣式可確保品牌形象的一致性。IronPDF的 Chromium 引擎提供完整的 Bootstrap 支援,而ComPDFKit的 API 導向方法在處理複雜的 CSS 框架時則顯露其局限性。
IronPDF如何處理 Bootstrap 樣式?
IronPDF 採用 Chromium 的渲染引擎,在所有版本(Bootstrap 5、4 及 3)中皆提供像素級精準的 Bootstrap 支援。 這個函式庫可以無縫處理 Flexbox 佈局、CSS Grid、反應式實用程式和自訂元件。 如需進階 CSS 渲染相關資訊,請參閱渲染選項指南。
using IronPdf;
// Set license
IronPdf.License.LicenseKey = "License-Key";
var renderer = new ChromePdfRenderer();
// Bootstrap 5 e-commerce invoice example
string bootstrapInvoice = @"
<!DOCTYPE html>
<html lang='en'>
<head>
<meta charset='utf-8'>
<meta name='viewport' content='width=device-width, initial-scale=1'>
<link href='___PROTECTED_URL_138___ rel='stylesheet'>
<style>
@page { margin: 20mm; }
.invoice-header { border-bottom: 3px solid #0d6efd; }
.product-row { border-bottom: 1px solid #dee2e6; }
.total-section { background-color: #f8f9fa; }
</style>
</head>
<body>
<div class='container-fluid p-4'>
<div class='row invoice-header pb-4 mb-4'>
<div class='col-8'>
<h1 class='display-4 text-primary'>INVOICE</h1>
<p class='text-muted mb-0'>TechStore Inc.</p>
<p class='text-muted mb-0'>123 Commerce Street, Tech City, TC 12345</p>
<p class='text-muted'>Email: sales@techstore.com | Phone: (555) 123-4567</p>
</div>
<div class='col-4 text-end'>
<p class='mb-1'><strong>Invoice #:</strong> INV-2024-1089</p>
<p class='mb-1'><strong>Date:</strong> October 27, 2024</p>
<p class='mb-1'><strong>Due Date:</strong> November 27, 2024</p>
<span class='badge bg-success'>PAID</span>
</div>
</div>
<div class='row mb-4'>
<div class='col-6'>
<h5 class='text-primary'>Bill To:</h5>
<p class='mb-1'><strong>Acme Corporation</strong></p>
<p class='mb-1'>456 Business Ave</p>
<p class='mb-1'>Enterprise City, EC 67890</p>
<p class='mb-0'>contact@acmecorp.com</p>
</div>
<div class='col-6 text-end'>
<h5 class='text-primary'>Payment Method:</h5>
<p class='mb-1'>Credit Card ending in 4242</p>
<p class='mb-0'>Transaction ID: TXN-9876543210</p>
</div>
</div>
<div class='row mb-4'>
<div class='col-12'>
<table class='table'>
<thead class='table-primary'>
<tr>
<th scope='col'>#</th>
<th scope='col'>Product</th>
<th scope='col'>Description</th>
<th scope='col' class='text-center'>Qty</th>
<th scope='col' class='text-end'>Unit Price</th>
<th scope='col' class='text-end'>Amount</th>
</tr>
</thead>
<tbody>
<tr class='product-row'>
<td>1</td>
<td><strong>IronPDF Pro License</strong></td>
<td>Professional developer license with 1 year support</td>
<td class='text-center'>1</td>
<td class='text-end'>$2,999.00</td>
<td class='text-end'><strong>$2,999.00</strong></td>
</tr>
<tr class='product-row'>
<td>2</td>
<td><strong>Priority Support</strong></td>
<td>24/7 priority technical support package</td>
<td class='text-center'>1</td>
<td class='text-end'>$999.00</td>
<td class='text-end'><strong>$999.00</strong></td>
</tr>
<tr class='product-row'>
<td>3</td>
<td><strong>Training Package</strong></td>
<td>On-site developer training (2 days)</td>
<td class='text-center'>1</td>
<td class='text-end'>$1,500.00</td>
<td class='text-end'><strong>$1,500.00</strong></td>
</tr>
</tbody>
</table>
</div>
</div>
<div class='row justify-content-end mb-4'>
<div class='col-md-6'>
<div class='card total-section'>
<div class='card-body'>
<div class='row mb-2'>
<div class='col-6'><strong>Subtotal:</strong></div>
<div class='col-6 text-end'>$5,498.00</div>
</div>
<div class='row mb-2'>
<div class='col-6'><strong>Tax (8.5%):</strong></div>
<div class='col-6 text-end'>$467.33</div>
</div>
<div class='row mb-2'>
<div class='col-6 text-success'><strong>Discount (10%):</strong></div>
<div class='col-6 text-end text-success'>-$549.80</div>
</div>
<hr>
<div class='row'>
<div class='col-6'><h4 class='text-primary'>Total:</h4></div>
<div class='col-6 text-end'><h4 class='text-primary'>$5,415.53</h4></div>
</div>
</div>
</div>
</div>
</div>
<div class='row mb-4'>
<div class='col-12'>
<div class='alert alert-info' role='alert'>
<h6 class='alert-heading'>Payment Terms</h6>
<p class='mb-0'>Payment is due within 30 days. Late payments may incur a 1.5% monthly interest charge. Thank you for your business!</p>
</div>
</div>
</div>
<div class='row border-top pt-3'>
<div class='col-12 text-center text-muted'>
<small>TechStore Inc. | Tax ID: 12-3456789 | All prices in USD</small>
</div>
</div>
</div>
</body>
</html>";
// Render PDF with optimized settings
var pdf = renderer.RenderHtmlAsPdf(bootstrapInvoice);
// Add metadata for document management
pdf.MetaData.Title = "Invoice INV-2024-1089";
pdf.MetaData.Author = "TechStore Inc.";
pdf.MetaData.Subject = "Sales Invoice";
pdf.MetaData.Keywords = "invoice, payment, e-commerce";
// Save the invoice
pdf.SaveAs("invoice-with-bootstrap.pdf");
using IronPdf;
// Set license
IronPdf.License.LicenseKey = "License-Key";
var renderer = new ChromePdfRenderer();
// Bootstrap 5 e-commerce invoice example
string bootstrapInvoice = @"
<!DOCTYPE html>
<html lang='en'>
<head>
<meta charset='utf-8'>
<meta name='viewport' content='width=device-width, initial-scale=1'>
<link href='___PROTECTED_URL_138___ rel='stylesheet'>
<style>
@page { margin: 20mm; }
.invoice-header { border-bottom: 3px solid #0d6efd; }
.product-row { border-bottom: 1px solid #dee2e6; }
.total-section { background-color: #f8f9fa; }
</style>
</head>
<body>
<div class='container-fluid p-4'>
<div class='row invoice-header pb-4 mb-4'>
<div class='col-8'>
<h1 class='display-4 text-primary'>INVOICE</h1>
<p class='text-muted mb-0'>TechStore Inc.</p>
<p class='text-muted mb-0'>123 Commerce Street, Tech City, TC 12345</p>
<p class='text-muted'>Email: sales@techstore.com | Phone: (555) 123-4567</p>
</div>
<div class='col-4 text-end'>
<p class='mb-1'><strong>Invoice #:</strong> INV-2024-1089</p>
<p class='mb-1'><strong>Date:</strong> October 27, 2024</p>
<p class='mb-1'><strong>Due Date:</strong> November 27, 2024</p>
<span class='badge bg-success'>PAID</span>
</div>
</div>
<div class='row mb-4'>
<div class='col-6'>
<h5 class='text-primary'>Bill To:</h5>
<p class='mb-1'><strong>Acme Corporation</strong></p>
<p class='mb-1'>456 Business Ave</p>
<p class='mb-1'>Enterprise City, EC 67890</p>
<p class='mb-0'>contact@acmecorp.com</p>
</div>
<div class='col-6 text-end'>
<h5 class='text-primary'>Payment Method:</h5>
<p class='mb-1'>Credit Card ending in 4242</p>
<p class='mb-0'>Transaction ID: TXN-9876543210</p>
</div>
</div>
<div class='row mb-4'>
<div class='col-12'>
<table class='table'>
<thead class='table-primary'>
<tr>
<th scope='col'>#</th>
<th scope='col'>Product</th>
<th scope='col'>Description</th>
<th scope='col' class='text-center'>Qty</th>
<th scope='col' class='text-end'>Unit Price</th>
<th scope='col' class='text-end'>Amount</th>
</tr>
</thead>
<tbody>
<tr class='product-row'>
<td>1</td>
<td><strong>IronPDF Pro License</strong></td>
<td>Professional developer license with 1 year support</td>
<td class='text-center'>1</td>
<td class='text-end'>$2,999.00</td>
<td class='text-end'><strong>$2,999.00</strong></td>
</tr>
<tr class='product-row'>
<td>2</td>
<td><strong>Priority Support</strong></td>
<td>24/7 priority technical support package</td>
<td class='text-center'>1</td>
<td class='text-end'>$999.00</td>
<td class='text-end'><strong>$999.00</strong></td>
</tr>
<tr class='product-row'>
<td>3</td>
<td><strong>Training Package</strong></td>
<td>On-site developer training (2 days)</td>
<td class='text-center'>1</td>
<td class='text-end'>$1,500.00</td>
<td class='text-end'><strong>$1,500.00</strong></td>
</tr>
</tbody>
</table>
</div>
</div>
<div class='row justify-content-end mb-4'>
<div class='col-md-6'>
<div class='card total-section'>
<div class='card-body'>
<div class='row mb-2'>
<div class='col-6'><strong>Subtotal:</strong></div>
<div class='col-6 text-end'>$5,498.00</div>
</div>
<div class='row mb-2'>
<div class='col-6'><strong>Tax (8.5%):</strong></div>
<div class='col-6 text-end'>$467.33</div>
</div>
<div class='row mb-2'>
<div class='col-6 text-success'><strong>Discount (10%):</strong></div>
<div class='col-6 text-end text-success'>-$549.80</div>
</div>
<hr>
<div class='row'>
<div class='col-6'><h4 class='text-primary'>Total:</h4></div>
<div class='col-6 text-end'><h4 class='text-primary'>$5,415.53</h4></div>
</div>
</div>
</div>
</div>
</div>
<div class='row mb-4'>
<div class='col-12'>
<div class='alert alert-info' role='alert'>
<h6 class='alert-heading'>Payment Terms</h6>
<p class='mb-0'>Payment is due within 30 days. Late payments may incur a 1.5% monthly interest charge. Thank you for your business!</p>
</div>
</div>
</div>
<div class='row border-top pt-3'>
<div class='col-12 text-center text-muted'>
<small>TechStore Inc. | Tax ID: 12-3456789 | All prices in USD</small>
</div>
</div>
</div>
</body>
</html>";
// Render PDF with optimized settings
var pdf = renderer.RenderHtmlAsPdf(bootstrapInvoice);
// Add metadata for document management
pdf.MetaData.Title = "Invoice INV-2024-1089";
pdf.MetaData.Author = "TechStore Inc.";
pdf.MetaData.Subject = "Sales Invoice";
pdf.MetaData.Keywords = "invoice, payment, e-commerce";
// Save the invoice
pdf.SaveAs("invoice-with-bootstrap.pdf");
Imports IronPdf
' Set license
IronPdf.License.LicenseKey = "License-Key"
Dim renderer As New ChromePdfRenderer()
' Bootstrap 5 e-commerce invoice example
Dim bootstrapInvoice As String = "
<!DOCTYPE html>
<html lang='en'>
<head>
<meta charset='utf-8'>
<meta name='viewport' content='width=device-width, initial-scale=1'>
<link href='___PROTECTED_URL_138___ rel='stylesheet'>
<style>
@page { margin: 20mm; }
.invoice-header { border-bottom: 3px solid #0d6efd; }
.product-row { border-bottom: 1px solid #dee2e6; }
.total-section { background-color: #f8f9fa; }
</style>
</head>
<body>
<div class='container-fluid p-4'>
<div class='row invoice-header pb-4 mb-4'>
<div class='col-8'>
<h1 class='display-4 text-primary'>INVOICE</h1>
<p class='text-muted mb-0'>TechStore Inc.</p>
<p class='text-muted mb-0'>123 Commerce Street, Tech City, TC 12345</p>
<p class='text-muted'>Email: sales@techstore.com | Phone: (555) 123-4567</p>
</div>
<div class='col-4 text-end'>
<p class='mb-1'><strong>Invoice #:</strong> INV-2024-1089</p>
<p class='mb-1'><strong>Date:</strong> October 27, 2024</p>
<p class='mb-1'><strong>Due Date:</strong> November 27, 2024</p>
<span class='badge bg-success'>PAID</span>
</div>
</div>
<div class='row mb-4'>
<div class='col-6'>
<h5 class='text-primary'>Bill To:</h5>
<p class='mb-1'><strong>Acme Corporation</strong></p>
<p class='mb-1'>456 Business Ave</p>
<p class='mb-1'>Enterprise City, EC 67890</p>
<p class='mb-0'>contact@acmecorp.com</p>
</div>
<div class='col-6 text-end'>
<h5 class='text-primary'>Payment Method:</h5>
<p class='mb-1'>Credit Card ending in 4242</p>
<p class='mb-0'>Transaction ID: TXN-9876543210</p>
</div>
</div>
<div class='row mb-4'>
<div class='col-12'>
<table class='table'>
<thead class='table-primary'>
<tr>
<th scope='col'>#</th>
<th scope='col'>Product</th>
<th scope='col'>Description</th>
<th scope='col' class='text-center'>Qty</th>
<th scope='col' class='text-end'>Unit Price</th>
<th scope='col' class='text-end'>Amount</th>
</tr>
</thead>
<tbody>
<tr class='product-row'>
<td>1</td>
<td><strong>IronPDF Pro License</strong></td>
<td>Professional developer license with 1 year support</td>
<td class='text-center'>1</td>
<td class='text-end'>$2,999.00</td>
<td class='text-end'><strong>$2,999.00</strong></td>
</tr>
<tr class='product-row'>
<td>2</td>
<td><strong>Priority Support</strong></td>
<td>24/7 priority technical support package</td>
<td class='text-center'>1</td>
<td class='text-end'>$999.00</td>
<td class='text-end'><strong>$999.00</strong></td>
</tr>
<tr class='product-row'>
<td>3</td>
<td><strong>Training Package</strong></td>
<td>On-site developer training (2 days)</td>
<td class='text-center'>1</td>
<td class='text-end'>$1,500.00</td>
<td class='text-end'><strong>$1,500.00</strong></td>
</tr>
</tbody>
</table>
</div>
</div>
<div class='row justify-content-end mb-4'>
<div class='col-md-6'>
<div class='card total-section'>
<div class='card-body'>
<div class='row mb-2'>
<div class='col-6'><strong>Subtotal:</strong></div>
<div class='col-6 text-end'>$5,498.00</div>
</div>
<div class='row mb-2'>
<div class='col-6'><strong>Tax (8.5%):</strong></div>
<div class='col-6 text-end'>$467.33</div>
</div>
<div class='row mb-2'>
<div class='col-6 text-success'><strong>Discount (10%):</strong></div>
<div class='col-6 text-end text-success'>-$549.80</div>
</div>
<hr>
<div class='row'>
<div class='col-6'><h4 class='text-primary'>Total:</h4></div>
<div class='col-6 text-end'><h4 class='text-primary'>$5,415.53</h4></div>
</div>
</div>
</div>
</div>
</div>
<div class='row mb-4'>
<div class='col-12'>
<div class='alert alert-info' role='alert'>
<h6 class='alert-heading'>Payment Terms</h6>
<p class='mb-0'>Payment is due within 30 days. Late payments may incur a 1.5% monthly interest charge. Thank you for your business!</p>
</div>
</div>
</div>
<div class='row border-top pt-3'>
<div class='col-12 text-center text-muted'>
<small>TechStore Inc. | Tax ID: 12-3456789 | All prices in USD</small>
</div>
</div>
</div>
</body>
</html>"
' Render PDF with optimized settings
Dim pdf = renderer.RenderHtmlAsPdf(bootstrapInvoice)
' Add metadata for document management
pdf.MetaData.Title = "Invoice INV-2024-1089"
pdf.MetaData.Author = "TechStore Inc."
pdf.MetaData.Subject = "Sales Invoice"
pdf.MetaData.Keywords = "invoice, payment, e-commerce"
' Save the invoice
pdf.SaveAs("invoice-with-bootstrap.pdf")
展示的 Bootstrap 主要功能:
-網格系統:用於響應式佈局結構的 row 和 col-* 類
-排版: display-4、@@----CODE-15299--@@、h5 用於分層文字樣式
- 用於結構化資料展示的表格:
table、table-primary、table-hover-卡片:card和card-body,用於背景樣式的總計部分 -徽章:badge bg-success用於支付狀態指示器 -提醒:alert alert-info用於付款條款通知 -實用程式:text-end、text-center、mb-*、pb-*間距實用程式 - 自訂樣式:結合 Bootstrap 類別以實現專屬發票設計
IronPDF 的 Chromium 引擎確保完美呈現 Bootstrap 元件:
-網格系統:用於響應式佈局的 row 和 col-* 類
-排版:display-4, text-muted, h5 用於層級樣式
-表:table、table-primary、table-hover,用於結構化數據
-卡片:card 和 card-body 用於樣式化部分
-徽章:badge bg-success 用於狀態指示器
-通知:alert alert-info
-實用程式:text-end,text-center,間距實用程序
- 自訂樣式:結合 Bootstrap 進行發票設計
針對網頁字型與圖示,IronPDF 提供完整的自訂排版支援。 若需排除 Bootstrap 版面配置的問題,請參閱 Bootstrap Flex CSS 疑難排解。 關於視口與Zoom設定,正確的配置可確保響應式佈局能正確渲染。
ComPDFKit在搭配 Bootstrap 使用時有哪些限制?
ComPDFKit 的 HTML 至 PDF 轉換依賴外部 API 呼叫,而非內嵌式渲染。 雖然此方法可處理基本的 Bootstrap 樣式,但會帶來幾項限制:
- 網路依賴性:需向外部服務發送 HTTP 請求
- CSS 框架支援:可能無法完全支援複雜的 Flexbox 或 CSS Grid 佈局
- 渲染一致性:結果可能因 API 服務的實作方式而有所不同
- 自訂樣式:對 Bootstrap 元件渲染的控制有限
- 效能:網路延遲會為文件生成增加額外負擔
對於需要可靠的 Bootstrap 渲染並能完全控制樣式與版面的應用程式,原生 Chromium 渲染能提供更優異的效果。IronPDF的整合式解決方案在維持完整 CSS 框架相容性的同時,消除了對外部元件的依賴。
如何在 PDF 檔案中加入浮水印?
對 PDF 文件進行浮水印處理有助於保護文件完整性、主張所有權並增強安全性。 浮水印可以是出現在背景或前景的文字、標誌或圖片。 它們在傳達文件狀態或創建者身分等重要資訊的同時,亦能防止未經授權的使用與散佈。
如何使用IronPDF添加浮水印?
IronPDF 提供直觀的程式化水印套用功能,可將水印套用至 PDF 文件。 此功能已整合至函式庫中,讓開發人員能透過 C# 程式碼套用水印。 針對背景與前景的定位,IronPDF 提供靈活的定位選項。
using IronPdf;
using IronPdf.Editing;
class Program
{
static void Main()
{
License.LicenseKey = "License-Code";
string watermarkHtml = @"
<img style='width: 500px;' src='C:\Users\Tayyab Ali\Desktop\watermark.png'>
<h1>IronPDF Watermark</h1>";
ChromePdfRenderer renderer = new ChromePdfRenderer();
PdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>It's a PDF with a watermark</h1>");
// Apply watermark with 30 degrees rotation and 50% opacity
pdf.ApplyWatermark(watermarkHtml, rotation: 30, opacity: 50);
pdf.SaveAs("Confidential.pdf");
}
}
using IronPdf;
using IronPdf.Editing;
class Program
{
static void Main()
{
License.LicenseKey = "License-Code";
string watermarkHtml = @"
<img style='width: 500px;' src='C:\Users\Tayyab Ali\Desktop\watermark.png'>
<h1>IronPDF Watermark</h1>";
ChromePdfRenderer renderer = new ChromePdfRenderer();
PdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>It's a PDF with a watermark</h1>");
// Apply watermark with 30 degrees rotation and 50% opacity
pdf.ApplyWatermark(watermarkHtml, rotation: 30, opacity: 50);
pdf.SaveAs("Confidential.pdf");
}
}
Imports IronPdf
Imports IronPdf.Editing
Friend Class Program
Shared Sub Main()
License.LicenseKey = "License-Code"
Dim watermarkHtml As String = "
<img style='width: 500px;' src='C:\Users\Tayyab Ali\Desktop\watermark.png'>
<h1>IronPDF Watermark</h1>"
Dim renderer As New ChromePdfRenderer()
Dim pdf As PdfDocument = renderer.RenderHtmlAsPdf("<h1>It's a PDF with a watermark</h1>")
' Apply watermark with 30 degrees rotation and 50% opacity
pdf.ApplyWatermark(watermarkHtml, rotation:= 30, opacity:= 50)
pdf.SaveAs("Confidential.pdf")
End Sub
End Class
! PDF 頁面左下角顯示紅色"CONFIDENTIAL"水印戳記和灰色"IronPDF Watermark"文字,示範了浮水印應用功能。
本範例使用 ChromePdfRenderer 從 HTML 建立 PDF。 ApplyWatermark 方法會套用包含圖像和標題的浮水印。 旋轉角度設定為 30 度,不透明度為 50%,以確保可見度同時不遮蔽內容。 生成的 PDF 檔案將儲存至指定路徑。
有哪些進階浮水印選項?
IronPDF 提供完整的浮水印功能:
- 基於 HTML 的浮水印:使用完整的 HTML/CSS 進行複雜設計
- 定位控制:3x3 網格定位系統
- 不透明度設定:微調透明度等級
- 旋轉選項:可設定任意角度以添加對角線浮水印
- 頁面選取:套用至所有頁面或特定範圍
- 多重浮水印:可依需求疊加不同浮水印
如何使用ComPDFKit添加浮水印?
ComPDFKit 提供透過該函式庫的方法,以程式化方式添加浮水印的功能。 此程式碼範例示範如何新增文字浮水印:
static private bool AddTextWatermark(CPDFDocument document)
{
CPDFWatermark watermark = document.InitWatermark(C_Watermark_Type.WATERMARK_TYPE_TEXT);
watermark.SetText("test");
watermark.SetFontName("Helvetica");
watermark.SetPages("0-3");
byte[] color = { 255, 0, 0 };
watermark.SetTextRGBColor(color);
watermark.SetScale(2);
watermark.SetRotation(0);
watermark.SetOpacity(120);
watermark.SetVertalign(C_Watermark_Vertalign.WATERMARK_VERTALIGN_CENTER);
watermark.SetHorizalign(C_Watermark_Horizalign.WATERMARK_HORIZALIGN_CENTER);
watermark.SetVertOffset(0);
watermark.SetHorizOffset(0);
watermark.SetFront(true);
watermark.SetFullScreen(true);
watermark.SetVerticalSpacing(10);
watermark.SetHorizontalSpacing(10);
watermark.CreateWatermark();
string path = "AddTextWatermarkTest.pdf";
if (!document.WriteToFilePath(path))
{
return false;
}
Console.WriteLine("Browse the changed file in " + path);
return true;
}
CPDFDocument document = CPDFDocument.InitWithFilePath("SamplePDF.pdf");
if (AddTextWatermark(document))
{
Console.WriteLine("Add text watermark done.");
}
else
{
Console.WriteLine("Add text watermark failed.");
}
static private bool AddTextWatermark(CPDFDocument document)
{
CPDFWatermark watermark = document.InitWatermark(C_Watermark_Type.WATERMARK_TYPE_TEXT);
watermark.SetText("test");
watermark.SetFontName("Helvetica");
watermark.SetPages("0-3");
byte[] color = { 255, 0, 0 };
watermark.SetTextRGBColor(color);
watermark.SetScale(2);
watermark.SetRotation(0);
watermark.SetOpacity(120);
watermark.SetVertalign(C_Watermark_Vertalign.WATERMARK_VERTALIGN_CENTER);
watermark.SetHorizalign(C_Watermark_Horizalign.WATERMARK_HORIZALIGN_CENTER);
watermark.SetVertOffset(0);
watermark.SetHorizOffset(0);
watermark.SetFront(true);
watermark.SetFullScreen(true);
watermark.SetVerticalSpacing(10);
watermark.SetHorizontalSpacing(10);
watermark.CreateWatermark();
string path = "AddTextWatermarkTest.pdf";
if (!document.WriteToFilePath(path))
{
return false;
}
Console.WriteLine("Browse the changed file in " + path);
return true;
}
CPDFDocument document = CPDFDocument.InitWithFilePath("SamplePDF.pdf");
if (AddTextWatermark(document))
{
Console.WriteLine("Add text watermark done.");
}
else
{
Console.WriteLine("Add text watermark failed.");
}
Private Shared Function AddTextWatermark(ByVal document As CPDFDocument) As Boolean
Dim watermark As CPDFWatermark = document.InitWatermark(C_Watermark_Type.WATERMARK_TYPE_TEXT)
watermark.SetText("test")
watermark.SetFontName("Helvetica")
watermark.SetPages("0-3")
Dim color() As Byte = { 255, 0, 0 }
watermark.SetTextRGBColor(color)
watermark.SetScale(2)
watermark.SetRotation(0)
watermark.SetOpacity(120)
watermark.SetVertalign(C_Watermark_Vertalign.WATERMARK_VERTALIGN_CENTER)
watermark.SetHorizalign(C_Watermark_Horizalign.WATERMARK_HORIZALIGN_CENTER)
watermark.SetVertOffset(0)
watermark.SetHorizOffset(0)
watermark.SetFront(True)
watermark.SetFullScreen(True)
watermark.SetVerticalSpacing(10)
watermark.SetHorizontalSpacing(10)
watermark.CreateWatermark()
Dim path As String = "AddTextWatermarkTest.pdf"
If Not document.WriteToFilePath(path) Then
Return False
End If
Console.WriteLine("Browse the changed file in " & path)
Return True
End Function
Private document As CPDFDocument = CPDFDocument.InitWithFilePath("SamplePDF.pdf")
If AddTextWatermark(document) Then
Console.WriteLine("Add text watermark done.")
Else
Console.WriteLine("Add text watermark failed.")
End If
! PDF 頁面,重複出現紅色"test"水印文本,中心帶有ComPDFKit標誌和"Page1"標籤,顯示ComPDFKit的水印輸出。
此範例使用 CPDFDocument 開啟現有的 PDF 檔案。 AddTextWatermark 方法初始化文字浮水印,設定文字內容、字型、顏色、縮放、旋轉、不透明度、對齊方式和間距等屬性。 浮水印將套用至指定頁面,並儲存至預設路徑。 圖片浮水印需要採用不同的處理方法,這增加了實作的複雜度。
如何建立符合 PDF/A 標準的文件?
PDF/A 是一種專為長期數位保存而設計的標準化 PDF 版本。 確保符合 PDF/A 標準,可保證未來能可靠地檢視與重現文件。 本節將探討如何利用這兩套函式庫建立符合 PDF/A 標準的文件。
IronPDF是如何建立 PDF/A 文件的?
IronPDF 簡化了將標準 PDF 轉換為符合 PDF/A 標準格式的流程。 此函式庫支援多種 PDF/A 標準,包括 PDF/A-1、PDF/A-2 及 PDF/A-3。有關 PDF/A 里程碑更新以及支援 ZUGFeRD 的 PDF/A-3 資訊,請參閱產品公告。
using IronPdf;
using System;
class Program
{
static void Main()
{
License.LicenseKey = "License-Key";
PdfDocument pdf = PdfDocument.FromFile("Source.pdf");
pdf.SaveAsPdfA("pdfa-compliant.pdf", PdfAVersions.PdfA3);
}
}
using IronPdf;
using System;
class Program
{
static void Main()
{
License.LicenseKey = "License-Key";
PdfDocument pdf = PdfDocument.FromFile("Source.pdf");
pdf.SaveAsPdfA("pdfa-compliant.pdf", PdfAVersions.PdfA3);
}
}
Imports IronPdf
Imports System
Friend Class Program
Shared Sub Main()
License.LicenseKey = "License-Key"
Dim pdf As PdfDocument = PdfDocument.FromFile("Source.pdf")
pdf.SaveAsPdfA("pdfa-compliant.pdf", PdfAVersions.PdfA3)
End Sub
End Class
過程包括
- 初始化 IronPDF:首先導入IronPDF函式庫並設定您的授權金鑰。
- 載入 PDF:使用 PdfDocument.FromFile 載入您的原始 PDF 檔案。
- 轉換並儲存:透過指定所需的 PDF/A 版本,將載入的 PDF 轉換為 PDF/A,並儲存生成的文件。
為何選擇 PDF/A 作為文件歸檔格式?
PDF/A 在長期保存方面具有多項優勢:
- 自包含文件:所有字型與資源均已內嵌
- 無外部依賴:消除對外部內容的依賴
- 標準化格式:通過 ISO 認證,適用於歸檔用途
- 元資料保留:保留文件屬性
- 視覺重現性:確保外觀隨時間推移保持一致
IronPDF 亦支援 PDF/UA 格式以滿足無障礙需求,確保文件符合《第 508 條》合規標準。
ComPDFKit是如何建立 PDF/A 文件的?
ComPDFKit 透過文件初始化、輸出路徑定義及轉換方法呼叫,提供可靠的 PDF/A 轉換功能。
static public bool CovertToPDFA1a(CPDFDocument document)
{
string convertToPDFA1aPath = "ConvertToPDFA1aTest.pdf";
if (!document.WritePDFAToFilePath(CPDFType.CPDFTypePDFA1a, convertToPDFA1aPath))
{
return false;
}
Console.WriteLine("Browse the changed file in " + convertToPDFA1aPath);
return true;
}
CPDFDocument document = CPDFDocument.InitWithFilePath("CommonFivePage.pdf");
if (CovertToPDFA1a(document))
{
Console.WriteLine("Convert to PDF/A-1a done.");
}
else
{
Console.WriteLine("Convert to PDF/A-1a failed.");
}
static public bool CovertToPDFA1a(CPDFDocument document)
{
string convertToPDFA1aPath = "ConvertToPDFA1aTest.pdf";
if (!document.WritePDFAToFilePath(CPDFType.CPDFTypePDFA1a, convertToPDFA1aPath))
{
return false;
}
Console.WriteLine("Browse the changed file in " + convertToPDFA1aPath);
return true;
}
CPDFDocument document = CPDFDocument.InitWithFilePath("CommonFivePage.pdf");
if (CovertToPDFA1a(document))
{
Console.WriteLine("Convert to PDF/A-1a done.");
}
else
{
Console.WriteLine("Convert to PDF/A-1a failed.");
}
Public Shared Function CovertToPDFA1a(ByVal document As CPDFDocument) As Boolean
Dim convertToPDFA1aPath As String = "ConvertToPDFA1aTest.pdf"
If Not document.WritePDFAToFilePath(CPDFType.CPDFTypePDFA1a, convertToPDFA1aPath) Then
Return False
End If
Console.WriteLine("Browse the changed file in " & convertToPDFA1aPath)
Return True
End Function
Private document As CPDFDocument = CPDFDocument.InitWithFilePath("CommonFivePage.pdf")
If CovertToPDFA1a(document) Then
Console.WriteLine("Convert to PDF/A-1a done.")
Else
Console.WriteLine("Convert to PDF/A-1a failed.")
End If
步驟包括
- 初始化文件:使用 CPDFDocument.InitWithFilePath 載入 PDF 文件。
- 設定輸出目錄:請確認輸出目錄是否存在,若不存在則需建立。
- 轉換為 PDF/A:使用 WritePDFAToFilePath 並指定 PDF/A 類型來執行轉換並儲存檔案。
如何在 PDF 檔案中加入數位簽章?
數位簽章用於驗證文件的真實性與完整性。 本節將示範如何使用這兩套函式庫來添加數位簽章。 關於完整的數位簽章實作,IronPDF 提供了詳盡的文件。
如何使用IronPDF簽署 PDF 文件?
IronPDF 提供簡單且有效的數位簽章應用程式。 此函式庫支援 X.509 憑證及 HSM 整合,以滿足 Enterprise 級安全需求。
using IronPdf;
using IronPdf.Signing;
class Program
{
static void Main(string[] args)
{
var simpleSignature = new PdfSignature("MyCert.p12", "newpassword");
simpleSignature.SignPdfFile("sample.pdf");
}
}
using IronPdf;
using IronPdf.Signing;
class Program
{
static void Main(string[] args)
{
var simpleSignature = new PdfSignature("MyCert.p12", "newpassword");
simpleSignature.SignPdfFile("sample.pdf");
}
}
Imports IronPdf
Imports IronPdf.Signing
Friend Class Program
Shared Sub Main(ByVal args() As String)
Dim simpleSignature = New PdfSignature("MyCert.p12", "newpassword")
simpleSignature.SignPdfFile("sample.pdf")
End Sub
End Class
過程包括
- 初始化 IronPDF:導入必要的IronPDF函式庫。
- 建立簽名:使用憑證檔案和密碼初始化 PdfSignature 物件。
- 簽署 PDF:使用 SignPdfFile 將簽名套用至 PDF 檔案。
IronPDF提供哪些進階簽署選項?
IronPDF 提供完整的數位簽章功能:
- 多種簽名類型:憑證式、視覺化及表單欄位簽名
- HSM 支援:硬體安全模組整合
- 時間戳記伺服器:為簽名添加可信的時間戳記
- 簽名外觀:自訂視覺化簽名呈現方式
- 驗證支援:透過程式碼驗證現有簽名
- 版本控制:保留簽名版本歷史記錄
若需排除數位簽章相關問題,請參閱數位簽章疑難排解指南。
如何使用ComPDFKit簽署 PDF 文件?
ComPDFKit 提供完整的數位簽章建立功能,並具備廣泛的自訂選項。
private static void CreateDigitalSignature(CPDFDocument document, string certificatePath, string password)
{
Console.WriteLine("--------------------");
Console.WriteLine("Create digital signature.");
CPDFSignatureCertificate certificate = CPDFPKCS12CertHelper.GetCertificateWithPKCS12Path("Certificate.pfx", "ComPDFKit");
CPDFPage page = document.PageAtIndex(0);
CPDFSignatureWidget signatureField = page.CreateWidget(C_WIDGET_TYPE.WIDGET_SIGNATUREFIELDS) as CPDFSignatureWidget;
signatureField.SetRect(new CRect(28, 420, 150, 370));
signatureField.SetWidgetBorderRGBColor(new byte[] { 0, 0, 0 });
signatureField.SetWidgetBgRGBColor(new byte[] { 150, 180, 210 });
signatureField.UpdateAp();
string name = GetGrantorFromDictionary(certificate.SubjectDict) + "\n";
string date = DateTime.Now.ToString("yyyy.MM.dd HH:mm:ss");
string reason = "I am the owner of the document.";
string location = certificate.SubjectDict["C"];
string DN = certificate.Subject;
CPDFSignatureConfig signatureConfig = new CPDFSignatureConfig
{
Text = GetGrantorFromDictionary(certificate.SubjectDict),
Content =
"Name: " + name + "\n" +
"Date: " + date + "\n" +
"Reason: " + reason + " \n" +
"Location: " + location + "\n" +
"DN: " + DN + "\n",
IsContentAlignLeft = false,
IsDrawLogo = true,
LogoBitmap = new Bitmap("Logo.png"),
TextColor = new float[] { 0, 0, 0 },
ContentColor = new float[] { 0, 0, 0 }
};
string filePath = document.FileName + "_Signed.pdf";
signatureField.UpdataApWithSignature(signatureConfig);
if (document.WriteSignatureToFilePath(signatureField,
filePath,
certificatePath, password,
location,
reason, CPDFSignaturePermissions.CPDFSignaturePermissionsNone))
{
Console.WriteLine("File saved in " + filePath);
Console.WriteLine("Create digital signature done.");
}
else
{
Console.WriteLine("Create digital signature failed.");
}
Console.WriteLine("--------------------");
}
private static void CreateDigitalSignature(CPDFDocument document, string certificatePath, string password)
{
Console.WriteLine("--------------------");
Console.WriteLine("Create digital signature.");
CPDFSignatureCertificate certificate = CPDFPKCS12CertHelper.GetCertificateWithPKCS12Path("Certificate.pfx", "ComPDFKit");
CPDFPage page = document.PageAtIndex(0);
CPDFSignatureWidget signatureField = page.CreateWidget(C_WIDGET_TYPE.WIDGET_SIGNATUREFIELDS) as CPDFSignatureWidget;
signatureField.SetRect(new CRect(28, 420, 150, 370));
signatureField.SetWidgetBorderRGBColor(new byte[] { 0, 0, 0 });
signatureField.SetWidgetBgRGBColor(new byte[] { 150, 180, 210 });
signatureField.UpdateAp();
string name = GetGrantorFromDictionary(certificate.SubjectDict) + "\n";
string date = DateTime.Now.ToString("yyyy.MM.dd HH:mm:ss");
string reason = "I am the owner of the document.";
string location = certificate.SubjectDict["C"];
string DN = certificate.Subject;
CPDFSignatureConfig signatureConfig = new CPDFSignatureConfig
{
Text = GetGrantorFromDictionary(certificate.SubjectDict),
Content =
"Name: " + name + "\n" +
"Date: " + date + "\n" +
"Reason: " + reason + " \n" +
"Location: " + location + "\n" +
"DN: " + DN + "\n",
IsContentAlignLeft = false,
IsDrawLogo = true,
LogoBitmap = new Bitmap("Logo.png"),
TextColor = new float[] { 0, 0, 0 },
ContentColor = new float[] { 0, 0, 0 }
};
string filePath = document.FileName + "_Signed.pdf";
signatureField.UpdataApWithSignature(signatureConfig);
if (document.WriteSignatureToFilePath(signatureField,
filePath,
certificatePath, password,
location,
reason, CPDFSignaturePermissions.CPDFSignaturePermissionsNone))
{
Console.WriteLine("File saved in " + filePath);
Console.WriteLine("Create digital signature done.");
}
else
{
Console.WriteLine("Create digital signature failed.");
}
Console.WriteLine("--------------------");
}
Imports Microsoft.VisualBasic
Private Shared Sub CreateDigitalSignature(ByVal document As CPDFDocument, ByVal certificatePath As String, ByVal password As String)
Console.WriteLine("--------------------")
Console.WriteLine("Create digital signature.")
Dim certificate As CPDFSignatureCertificate = CPDFPKCS12CertHelper.GetCertificateWithPKCS12Path("Certificate.pfx", "ComPDFKit")
Dim page As CPDFPage = document.PageAtIndex(0)
Dim signatureField As CPDFSignatureWidget = TryCast(page.CreateWidget(C_WIDGET_TYPE.WIDGET_SIGNATUREFIELDS), CPDFSignatureWidget)
signatureField.SetRect(New CRect(28, 420, 150, 370))
signatureField.SetWidgetBorderRGBColor(New Byte() { 0, 0, 0 })
signatureField.SetWidgetBgRGBColor(New Byte() { 150, 180, 210 })
signatureField.UpdateAp()
Dim name As String = GetGrantorFromDictionary(certificate.SubjectDict) & vbLf
Dim [date] As String = DateTime.Now.ToString("yyyy.MM.dd HH:mm:ss")
Dim reason As String = "I am the owner of the document."
Dim location As String = certificate.SubjectDict("C")
Dim DN As String = certificate.Subject
Dim signatureConfig As New CPDFSignatureConfig With {
.Text = GetGrantorFromDictionary(certificate.SubjectDict),
.Content = "Name: " & name & vbLf & "Date: " & [date] & vbLf & "Reason: " & reason & " " & vbLf & "Location: " & location & vbLf & "DN: " & DN & vbLf,
.IsContentAlignLeft = False,
.IsDrawLogo = True,
.LogoBitmap = New Bitmap("Logo.png"),
.TextColor = New Single() { 0, 0, 0 },
.ContentColor = New Single() { 0, 0, 0 }
}
Dim filePath As String = document.FileName & "_Signed.pdf"
signatureField.UpdataApWithSignature(signatureConfig)
If document.WriteSignatureToFilePath(signatureField, filePath, certificatePath, password, location, reason, CPDFSignaturePermissions.CPDFSignaturePermissionsNone) Then
Console.WriteLine("File saved in " & filePath)
Console.WriteLine("Create digital signature done.")
Else
Console.WriteLine("Create digital signature failed.")
End If
Console.WriteLine("--------------------")
End Sub
步驟包括
- 初始化文件與憑證:載入 PDF 文件,並使用 CPDFPKCS12CertHelper 取得憑證。
- 建立並設定簽名欄位:在 PDF 中新增簽名欄位,設定其屬性,並配置簽名詳細資訊。
- 套用簽名:使用 WriteSignatureToFilePath 套用簽名並儲存已簽署的 PDF 檔案。
如何從 PDF 擷取文字?
從 PDF 文件中擷取文字對於資料處理與分析至關重要。 本節將說明如何使用這兩套函式庫進行文字擷取。
IronPDF是如何擷取文字的?
IronPDF 提供從 PDF 文件中直接提取文字的功能。 此函式庫提供用於擷取所有文字或特定頁面內容的方法。 在解析 PDF 內容方面,IronPDF 支援結構化擷取。 開發人員在存取 PDF DOM 物件時,可擷取詳細的內容資訊。
using IronPdf;
using System.IO;
PdfDocument pdf = PdfDocument.FromFile("PDF File With Text.pdf");
string text = pdf.ExtractAllText();
File.WriteAllText("PDF Text.txt", text);
using IronPdf;
using System.IO;
PdfDocument pdf = PdfDocument.FromFile("PDF File With Text.pdf");
string text = pdf.ExtractAllText();
File.WriteAllText("PDF Text.txt", text);
Imports IronPdf
Imports System.IO
Private pdf As PdfDocument = PdfDocument.FromFile("PDF File With Text.pdf")
Private text As String = pdf.ExtractAllText()
File.WriteAllText("PDF Text.txt", text)
過程包括
- 初始化 IronPDF:導入IronPDF函式庫。
- 載入 PDF:使用 PdfDocument.FromFile 載入 PDF 檔案。
- 擷取文字:呼叫 ExtractAllText 函式以從 PDF 中擷取所有文字內容。
- 將文字儲存至檔案:使用標準檔案 I/O 操作,將擷取的文字寫入檔案。
有哪些進階文字擷取功能可用?
IronPDF 提供強大的文字擷取功能:
- 單頁擷取:從個別頁面擷取文字
- 結構化內容:存取包含格式資訊的文字
- 搜尋與替換:在 PDF 檔案中搜尋並替換文字
- 正規表達式支援:基於模式的文字擷取
- 基於座標的擷取:從特定區域擷取文字
- 語言支援:支援 UTF-8 及國際化字元
如需完整的文本閱讀範例,請參閱 PDF 文本閱讀指南。
ComPDFKit是如何擷取文字的?
ComPDFKit 提供從 PDF 文件中靈活提取文字的功能。
static private bool PDFToText(CPDFDocument document)
{
string path = "//PDFToText.txt";
if (!document.PdfToText("1-" + document.PageCount.ToString(), path))//Page ranges are counted from 1
{
return false;
}
Console.WriteLine("Browse the generated file in " + path);
return true;
}
static void Main(string[] args)
{
Console.WriteLine("Running PDFPage test sample…\r\n");
SDKLicenseHelper.LicenseVerify();
CPDFDocument document = CPDFDocument.InitWithFilePath("CommonFivePage.pdf");
if (PDFToText(document))
{
Console.WriteLine("PDF to text done.");
}
else
{
Console.WriteLine("PDF to text failed.");
}
Console.WriteLine("--------------------");
Console.WriteLine("Done!");
Console.WriteLine("--------------------");
Console.ReadLine();
}
static private bool PDFToText(CPDFDocument document)
{
string path = "//PDFToText.txt";
if (!document.PdfToText("1-" + document.PageCount.ToString(), path))//Page ranges are counted from 1
{
return false;
}
Console.WriteLine("Browse the generated file in " + path);
return true;
}
static void Main(string[] args)
{
Console.WriteLine("Running PDFPage test sample…\r\n");
SDKLicenseHelper.LicenseVerify();
CPDFDocument document = CPDFDocument.InitWithFilePath("CommonFivePage.pdf");
if (PDFToText(document))
{
Console.WriteLine("PDF to text done.");
}
else
{
Console.WriteLine("PDF to text failed.");
}
Console.WriteLine("--------------------");
Console.WriteLine("Done!");
Console.WriteLine("--------------------");
Console.ReadLine();
}
Imports Microsoft.VisualBasic
Private Shared Function PDFToText(ByVal document As CPDFDocument) As Boolean
Dim path As String = "//PDFToText.txt"
If Not document.PdfToText("1-" & document.PageCount.ToString(), path) Then 'Page ranges are counted from 1
Return False
End If
Console.WriteLine("Browse the generated file in " & path)
Return True
End Function
Shared Sub Main(ByVal args() As String)
Console.WriteLine("Running PDFPage test sample…" & vbCrLf)
SDKLicenseHelper.LicenseVerify()
Dim document As CPDFDocument = CPDFDocument.InitWithFilePath("CommonFivePage.pdf")
If PDFToText(document) Then
Console.WriteLine("PDF to text done.")
Else
Console.WriteLine("PDF to text failed.")
End If
Console.WriteLine("--------------------")
Console.WriteLine("Done!")
Console.WriteLine("--------------------")
Console.ReadLine()
End Sub
步驟如下
- 初始化文件:使用 CPDFDocument.InitWithFilePath 載入 PDF 文件。
- 擷取並儲存文字:使用 PdfToText 從指定的頁碼範圍擷取文字,並將其儲存至檔案。
真實世界的使用案例情境
了解何時使用各函式庫,有助於開發人員根據專案需求做出明智的決策。 以下情境說明了各函式庫在實際應用中的優勢所在。
何時該選擇 IronPDF?
Enterprise文件生成系統 某金融服務公司需要每月生成超過 50,000 份對帳單,這些對帳單具有複雜的版面配置、圖表,並須符合監管合規要求。
IronPDF 的優勢:
- 效能:支援非同步/多執行緒,可高效處理大量資料
- 合規性:內建 PDF/A 與 PDF/UA 以符合法規要求
- 圖表:用於財務視覺化的原生 JavaScript 圖表渲染
- 安全性:針對敏感資料提供進階加密
- 技術支援:針對生產環境問題提供每週 5 天、每日 24 小時的工程支援
SaaS 發票生成平台 一個多租戶 SaaS 平台,能透過自訂範本為數千名客戶生成品牌化發票。
IronPDF 的優勢:
- HTML/CSS 支援:品牌化範本完全相容於 Bootstrap
- 效能:採用 Docker 部署以實現可擴展架構
- 自訂功能:用於品牌標識的頁首/頁尾及浮水印
- API 設計:簡潔的 API 可縮短開發時間
- 雲端就緒:原生支援 Azure 與 AWS
何時應考慮使用 ComPDFKit?
基礎 PDF 檢視器應用程式 一款桌面應用程式,需具備 PDF 檢視與基本註解功能,且無需 HTML 轉換需求。
ComPDFKit 的優勢:
- 檢視器元件:內建檢視功能
- 註解工具:原生註解支援
- 簡易整合:無需 HTML 即可直接操作 PDF
- 離線運作:核心功能無需網路連線
文件歸檔系統 一款專注於 PDF 組織與基本編輯功能的內部文件管理系統。
ComPDFKit 的優勢:
- 檔案處理:強大的 PDF 合併/分割功能
- 基本編輯:文字與圖片修改工具
- 傳統做法:以 PDF 為中心的 API 設計
有哪些授權選項?
IronPDF 與ComPDFKit的授權模式在實施方式與使用條款上有所不同。 了解這些差異有助於開發人員根據專案需求與預算,選擇合適的工具。
IronPDF提供哪些授權選項?
IronPDF 採用透明的商業授權模式:
授權類型:
- Lite License ($749):1 名開發者、1 個地點、1 個專案
- Plus License ($1,499):3 名開發人員、3 個地點、3 個專案
- Professional License ($2,999):10 名開發人員、10 個地點、10 個專案
- Enterprise/OEM:不限部署次數的客製化定價
主要優勢:
IronPDF 的商業模式確保 Enterprise 能獲得專屬支援、完整的文件,以及用於 Professional PDF 生成與處理的高階功能。 透明的定價結構消除了隱藏成本,並提供預算可預測性。
ComPDFKit提供哪些授權選項?
ComPDFKit 採用靈活的授權模式,以滿足不同的商業需求:
授權選項:
- 永久授權:一次性付款即可終身使用 SDK
- 訂閱授權:定期付款並享有持續更新
- 報價制:根據專案需求提供客製化報價
注意事項:
- 變動成本:報價需直接聯繫洽詢
- 更新費用:版本更新的可選費用
- 支援套件:獨立的支援協議要求
- API 使用限制:HTML 轉換 API 將產生額外費用
有哪些文件與支援資源可用?
IronPDF提供哪些支援?
IronPDF 提供 文件與支援基礎架構:
文件資源:
- 完整指南:涵蓋所有功能的 500 多個程式碼範例
- API 參考:包含
IntelliSense支援的完整 API 文檔 - 教學指南:針對常見情境的逐步教學指南
- 疑難排解:針對已知問題的詳盡疑難排解指南
- 平台指南:針對 Windows、Linux、macOS、Azure 及 Docker 的專屬指南
支援管道:
ComPDFKit提供哪些支援?
ComPDFKit 提供基礎文件與支援資源:
文件說明:
- 入門指南:基本設定說明
- API 參考:標準方法文件
- 範例程式碼:針對核心功能的有限範例
- 平台文件:基礎平台整合指南
支援選項:
- 電子郵件支援:於標準營業時間內回覆
- 技術支援:基礎故障排除協助
- 社群論壇:由使用者驅動的支援社群
雖然這兩套函式庫均提供文件與技術支援,但IronPDF提供的資源顯著更為完備,回應速度更快,並具備對生產環境部署至關重要的直接工程支援。
效能與最佳化考量
效能會影響生產系統的可行性。 了解各函式庫的優化能力,有助於系統架構師設計出高效的解決方案。
IronPDF如何優化效能?
IronPDF 提供廣泛的效能優化功能:
架構優勢:
- 原生 Chrome 引擎:經過優化的 C++ 渲染引擎
- 記憶體管理:高效處理大型文件
- 執行緒安全性:專為並發式網頁應用程式打造
- 資源池:可重複使用的渲染實例
效能特色:
基準測試(生成 50 頁文件):
- 單執行緒:平均 2.3 秒
- 多執行緒(8 核心):每份文件 0.4 秒
- 記憶體使用量:峰值 180MB
- 並發請求:100+ 同時渲染
ComPDFKit的效能特點為何?
ComPDFKit 針對基本操作提供標準效能:
效能概況:
- 同步處理:傳統的阻塞式操作
- 記憶體使用量:處理複雜文件時消耗較高
- 並行處理:僅支援有限的同時操作
- HTML 轉換:網路延遲會增加 1 至 3 秒
限制條件:
- 無內建非同步支援
- 有限的執行緒相關文件
- API 呼叫會引入網路開銷
- 資源管理需手動實作
Enterprise整合模式
生產系統需要特定的架構模式,以確保可靠性和可擴展性。 了解整合方法有助於團隊實現可靠的解決方案。
如何在微服務中實作 IronPDF?
IronPDF 支援現代架構模式:
容器化 PDF 服務:
// Dockerfile forIronPDFmicroservice
FROM mcr.microsoft.com/dotnet/aspnet:6.0
RUN apt-get update && apt-get install -y \
libgdiplus \
libc6-dev \
libx11-6
COPY . /app
WORKDIR /app
ENTRYPOINT ["dotnet", "PdfService.dll"]
// Dockerfile forIronPDFmicroservice
FROM mcr.microsoft.com/dotnet/aspnet:6.0
RUN apt-get update && apt-get install -y \
libgdiplus \
libc6-dev \
libx11-6
COPY . /app
WORKDIR /app
ENTRYPOINT ["dotnet", "PdfService.dll"]
The provided code is a Dockerfile, which is not written in C# and therefore cannot be directly converted to VB.NET. Dockerfiles are used to define the environment and instructions for building Docker images, and they do not have a direct equivalent in VB.NET. If you have any C# code that needs conversion to VB.NET, please provide that, and I will be happy to assist.
可擴展的 API 實作:
[ApiController]
[Route("api/[controller]")]
public class PdfController : ControllerBase
{
private readonly ChromePdfRenderer _renderer;
public PdfController()
{
_renderer = new ChromePdfRenderer();
// Configure for production
_renderer.RenderingOptions.EnableJavaScript = true;
_renderer.RenderingOptions.RenderDelay = 500;
}
[HttpPost("generate")]
public async Task<IActionResult> GeneratePdf([FromBody] PdfRequest request)
{
try
{
var pdf = await _renderer.RenderHtmlAsPdfAsync(request.Html);
// Apply security if needed
if (request.RequirePassword)
{
pdf.SecuritySettings.SetPassword(request.Password);
}
var stream = pdf.Stream;
return File(stream, "application/pdf", request.FileName);
}
catch (Exception ex)
{
//完成error handling
return StatusCode(500, new { error = ex.Message });
}
}
}
[ApiController]
[Route("api/[controller]")]
public class PdfController : ControllerBase
{
private readonly ChromePdfRenderer _renderer;
public PdfController()
{
_renderer = new ChromePdfRenderer();
// Configure for production
_renderer.RenderingOptions.EnableJavaScript = true;
_renderer.RenderingOptions.RenderDelay = 500;
}
[HttpPost("generate")]
public async Task<IActionResult> GeneratePdf([FromBody] PdfRequest request)
{
try
{
var pdf = await _renderer.RenderHtmlAsPdfAsync(request.Html);
// Apply security if needed
if (request.RequirePassword)
{
pdf.SecuritySettings.SetPassword(request.Password);
}
var stream = pdf.Stream;
return File(stream, "application/pdf", request.FileName);
}
catch (Exception ex)
{
//完成error handling
return StatusCode(500, new { error = ex.Message });
}
}
}
Imports Microsoft.AspNetCore.Mvc
<ApiController>
<Route("api/[controller]")>
Public Class PdfController
Inherits ControllerBase
Private ReadOnly _renderer As ChromePdfRenderer
Public Sub New()
_renderer = New ChromePdfRenderer()
' Configure for production
_renderer.RenderingOptions.EnableJavaScript = True
_renderer.RenderingOptions.RenderDelay = 500
End Sub
<HttpPost("generate")>
Public Async Function GeneratePdf(<FromBody> request As PdfRequest) As Task(Of IActionResult)
Try
Dim pdf = Await _renderer.RenderHtmlAsPdfAsync(request.Html)
' Apply security if needed
If request.RequirePassword Then
pdf.SecuritySettings.SetPassword(request.Password)
End If
Dim stream = pdf.Stream
Return File(stream, "application/pdf", request.FileName)
Catch ex As Exception
' Complete error handling
Return StatusCode(500, New With {.error = ex.Message})
End Try
End Function
End Class
優勢:
- 水平擴展:依需求新增執行個體
- 故障隔離:服務故障不會影響系統
- 資源控制:透過容器限制防止資源耗盡
- 部署靈活性:支援 Kubernetes、Docker Swarm
關於ComPDFKitEnterprise 整合功能?
ComPDFKit 需要採用傳統的整合方式:
- 單體式設計:與應用程式緊密耦合的函式庫
- 擴展限制:僅支援垂直擴展
- 資源共享:多租戶情境中的潛在衝突
- API 依賴性:外部服務需求使架構更為複雜
安全性與合規性功能
Enterprise級應用程式需要可靠的安全功能,以符合法規要求並保護資料安全。
IronPDF如何處理安全性?
IronPDF 提供完整的安全功能:
加密選項:
合規功能:
實作範例:
// Secure document generation
var pdf = renderer.RenderHtmlAsPdf(htmlContent);
// Apply complete security
pdf.SecuritySettings.SetPassword("user123");
pdf.SecuritySettings.SetOwnerPassword("owner456");
pdf.SecuritySettings.MakePdfDocumentReadOnly();
pdf.SecuritySettings.SetPdfSecuritySettings(
canPrint: true,
canCopy: false,
canModify: false
);
// Add digital signature
var signature = new PdfSignature("cert.pfx", "password");
pdf.SignWithSignature(signature);
// Ensure compliance
pdf.SaveAsPdfA("secure-compliant.pdf", PdfAVersions.PdfA3);
// Secure document generation
var pdf = renderer.RenderHtmlAsPdf(htmlContent);
// Apply complete security
pdf.SecuritySettings.SetPassword("user123");
pdf.SecuritySettings.SetOwnerPassword("owner456");
pdf.SecuritySettings.MakePdfDocumentReadOnly();
pdf.SecuritySettings.SetPdfSecuritySettings(
canPrint: true,
canCopy: false,
canModify: false
);
// Add digital signature
var signature = new PdfSignature("cert.pfx", "password");
pdf.SignWithSignature(signature);
// Ensure compliance
pdf.SaveAsPdfA("secure-compliant.pdf", PdfAVersions.PdfA3);
' Secure document generation
Dim pdf = renderer.RenderHtmlAsPdf(htmlContent)
' Apply complete security
pdf.SecuritySettings.SetPassword("user123")
pdf.SecuritySettings.SetOwnerPassword("owner456")
pdf.SecuritySettings.MakePdfDocumentReadOnly()
pdf.SecuritySettings.SetPdfSecuritySettings(
canPrint:=True,
canCopy:=False,
canModify:=False
)
' Add digital signature
Dim signature As New PdfSignature("cert.pfx", "password")
pdf.SignWithSignature(signature)
' Ensure compliance
pdf.SaveAsPdfA("secure-compliant.pdf", PdfAVersions.PdfA3)
ComPDFKit提供哪些安全性功能?
ComPDFKit 提供基本的安全功能:
- 密碼保護:基本使用者/擁有者密碼
- 加密:標準 PDF 加密
- 權限:有限的權限設定
- 數位簽章:基於憑證的簽署
然而,諸如 HSM 支援、資料淨化以及完整的合規工具等進階功能,則需額外實作。
我該選擇哪個 PDF 函式庫?
IronPDF 與ComPDFKit的比較顯示,兩者在不同的使用情境與需求下存在明顯差異。
為何IronPDF在 Enterprise 應用中表現卓越
對於需要以下功能的生產系統而言,IronPDF 無疑是首選:
技術卓越:
- 原生 HTML 渲染:Chromium 引擎確保完美轉換
- 效能:採用非同步/多執行緒技術,以處理大量資料
- 可靠性:適用於網頁應用的執行緒安全架構
- 整合:簡易的 API 可縮短開發時間
商業價值:
- 總持有成本:透明定價,無隱藏費用
- 支援基礎架構:24/5 工程支援服務,將停機時間降至最低
- 文件:500 多個範例加速開發進程
- 未來兼容性:定期更新與新增功能
真實開發者回饋: "IronPDF 徹底改變了發票生成系統。 開發人員每月處理超過 100,000 份文件,且完全沒有渲染問題。 "Bootstrap 的支援為我們節省了數週的開發時間。" ——《財星》500 強零售商資深 .NET 架構師
"在評估了多款函式庫後,IronPDF 的效能與技術支援使其成為不二之選。其非同步功能將處理時間縮短了 75%。"——金融服務業技術主管
何時ComPDFKit已足夠
ComPDFKit 可能適用於:
- 簡易 PDF 檢視:基礎桌面應用程式
- 範圍限制:不包含 HTML 轉換需求之專案
- 預算限制:當外部 API 費用在可接受範圍內時
- 基本操作:簡單的合併/分割需求
最終建議
對於以效能、可靠性及架構模式為優先考量、正在建置生產系統的高階 .NET 開發人員而言,IronPDF 提供了完整的解決方案。 其結合了技術能力、Enterprise級功能與卓越的支援基礎架構,確保專案能順利交付。
關鍵決策因素:
| 要求 | IronPDF | ComPDFKit | 獲獎作品 |
|---|---|---|---|
| HTML 至 PDF | 原生 Chromium | 外部 API | IronPDF |
| 表現 | 非同步/多執行緒 | 同步 | IronPDF |
| CSS 支援 | 完整 Bootstrap/Flexbox | 限額 | IronPDF |
| 文件 | 500+ 範例 | 基本的 | IronPDF |
| 支援 | 24/5 工程 | 僅限電子郵件 | IronPDF |
| Enterprise級功能 | 完成 | 限額 | IronPDF |
| 總費用 | 透明 | 變數 | IronPDF |
IronPDF 提供免費試用授權,供使用者測試該函式庫及其功能。IronPDF的授權價格自 749 美元起。此外,Iron Software 提供九個函式庫的捆綁方案,價格僅需購買兩個函式庫的費用,其中包含 IronXL、IronOCR 以及 IronPDF。
對於需要 Professional PDF 生成功能並具備 Enterprise 級支援的團隊,IronPDF 提供完整的解決方案。 憑藉與《財星》500 強企業合作的實績、完整的功能集,以及對開發者成功的堅定承諾,使其成為嚴謹 .NET 應用的最佳選擇。
常見問題解答
怎樣在 C# 中將 HTML 轉換為 PDF?
您可以使用 IronPDF 的 RenderHtmlAsPdf 方法將 HTML 字串轉換為 PDF。此方法適合將 HTML、CSS 和 JavaScript 轉換為高品質 PDF 文件。
使用 C# PDF 庫有何好處?
像 IronPDF 和 ComPDFKit 這樣的 C# PDF 庫能夠創建、修改和提取文本/圖像。他們支持表單處理、數位簽名和安全性等功能,提供跨平台的靈活性。
我可以在 C# 中為我的 PDF 增加安全性嗎?
可以,使用 IronPDF,您可以通過設置密碼、加密文件和添加數字簽名來增強 PDF 的安全性,以保護敏感信息。
ComPDFKit 如何處理 PDF 編輯和轉換?
ComPDFKit 提供強大的 PDF 編輯功能和轉換到各種格式,包括用於長期數字保存的 PDF/A,使其適合跨平台專案。
C# PDF 庫有哪些授權選項?
IronPDF 提供商業授權模式,具有永久授權,而 ComPDFKit 提供永久和訂閱授權,根據業務需求提供靈活性。
對於使用這些庫的開發者有哪些支持和資源?
IronPDF 提供全面的文檔和快速的客戶支持,使其適合企業級應用。ComPDFKit 也提供詳盡的文檔和技術支持。
IronPDF 和 ComPDFKit 在 HTML 轉 PDF 轉換方面如何比較?
IronPDF 在 HTML 轉 PDF 轉換方面表現出色,支持 HTML 字串、網址、ASPX 網頁表單和 MVC 視圖,而 ComPDFKit 提供更廣泛的 PDF 編輯和轉換功能。

