跳至頁尾內容
產品對比

IronPDF 與 XFINIUM.PDF:.NET 平台 HTML 轉 PDF 庫對比

IronPDF 擅長 HTML 轉換 PDF,它使用 Chromium 內核,並完全支援 CSS 和 JavaScript。相較之下,XFINIUM.PDF 專注於底層 PDF 操作,不進行原生 HTML 渲染,因此 IronPDF 更適合在 .NET 應用程式中產生基於 Web 的現代 PDF 檔案。

現代科技為開發者提供了更聰明的解決方案,自動化推動了軟體開發流程。 長期以來,處理C# PDF 檔案一直是開發人員面臨的挑戰。 創建 PDF 文件內容時必須考慮多種因素,將不同格式的內容轉換為 PDF時更是如此。 這些挑戰現在可以透過各種程式庫來解決,這些程式庫旨在幫助使用者閱讀、編寫、建立和轉換各種格式的 PDF 檔案。

本文比較了兩個適用於.NET.NET Core開發人員的常用 PDF 程式庫:

IronPDF庫

  • XFINIUM.PDF 庫

IronPDF 和 XFINIUM.PDF 都提供了在 .NET 和 .NET Core 中建立操作列印 PDF的方法。 您可以查看以下對兩個庫及其各自的PDF 轉換和處理功能的比較,從而做出明智的決定。

首先,讓我們來了解這兩個函式庫的功能,然後再進行比較。

XFINIUM.PDF 庫有哪些特色?

XFINIUM.PDF 庫是一個跨平台的 PDF 開發工具,既適用於初級 PDF 開發人員,也適用於高級 PDF 開發人員。 它允許您建立報告填寫 PDF 表單、建立 PDF 作品集、從 PDF 報告中刪除敏感數據,或將 PDF 報告轉換為多頁 TIFF 影像

XFINIUM.PDF 提供兩個版本:生成器版本,包括 PDF 產生和編輯功能;檢視器版本,增加了PDF 渲染PDF 檢視功能

XFINIUM.PDF 完全使用 C# 編寫,是完全託管的程式碼。 它按開發者授權,且無需支付版稅即可分發,讓您可以免費分發您的程式。

生成器版本和檢視器版本有什麼不同?

生成器版本是檢視器版本的子集。 它提供建立和編輯 PDF 的 PDF 功能,而檢視器版本則增加了PDF 渲染功能。 檢視器版可以將 PDF 頁面轉換為 RAW、BMP、GIF、JPG、PNG 和 TIFF 影像

XFINIUM.PDF 規範

主要特點包括:

安全

使用者密碼和所有者密碼

數位簽名

-獲得 X509 證書的批准和認證

條碼

  • 內建向量條碼引擎
  • 一維條碼:
    • Codabar、Code 11、Code 25、Code 39/93/128
    • 藥品:代碼 32,藥品代碼,PZN
  • 二維條碼:
    • DataMatrix 、QR、PDF417、微型 PDF417

如需更進階的條碼功能,請參考Ironbarcode 文檔,其中提供了完整的條碼產生和讀取功能。

內容擷取

-提取包含位置資訊的文本

底層 COS API

  • 新增、編輯和刪除 COS 對象 支援的類型:字串、數字、名稱、布林值、空值、陣列、字典、流

PDF渲染(僅限檢視器版本)

-將頁面渲染為影像:RAW、BMP、GIF、JPG、PNG、TIFF

IronPDF的主要特色是什麼?

IronPDF .NET PDF 程式庫簡化了 C# 程式設計師的 PDF 開發。 借助此工具,您可以輕鬆地為 .NET 建立核心 PDF 庫。

IronPDF 使用.NET Chromium 引擎將 HTML 頁面轉換為 PDF 檔案。 使用HTML to PDF,您無需複雜的 API 即可定位或設計 PDF。 支援標準網頁文檔,包括HTML、ASPX、JS、CSS 和圖像

您可以使用HTML5、CSS、JavaScript 和圖像來開發 .NET PDF 程式庫。 PDF 文件可以進行編輯、添加印章,並透過頁首和頁尾進行改進。 該庫能夠有效率地讀取 PDF 文字提取圖形

立即免費下載 IronPDF ,並在您的 .NET 專案中開始使用它。

IronPDF C# 庫的突出特點

主要特點包括:

產生 PDF 檔案(HTML 轉 PDF)

編輯現有PDF文檔

閱讀並填寫表單字段 提取圖形和文字 -使用新的 HTML 內容更新頁面 -新增邏輯或 HTML 頁首/頁尾

操作PDF文檔

-載入並解析現有PDF文件 合併和拆分文檔

轉換各種文件格式

列印並儲存

-從檔案、二進位數據、記憶體流保存/載入數據

IronPDF 支援所有主流作業系統和框架:

如何安裝 IronPDF C# 庫?

您可以透過以下四種方式下載並安裝 IronPDF:

  1. 使用 Visual Studio
  2. 開發人員命令提示符
  3. 直接下載NuGet 套件
  4. 下載 IronPDF .DLL 函式庫

使用 Visual Studio

Visual Studio 提供了 NuGet 套件管理器,用於在專案中安裝套件。 透過"專案"功能表或在"解決方案資源管理器"中右鍵單擊項目來存取它。

Visual Studio Project menu showing various options including 'Manage NuGet Packages' highlighted for package management.

圖 1.使用 Visual Studio 中的"專案"功能表存取 NuGet 套件管理器

Visual Studio Solution Explorer context menu showing the Manage NuGet Packages option highlighted in yellow

圖 2.在 Visual Studio 中使用上下文選單存取 NuGet 套件管理器

選定後,瀏覽並安裝 IronPDF 軟體包。

Visual Studio interface showing NuGet Package Manager with IronPDF library search results and installation options

圖 3.使用 Visual Studio 中的 NuGet 套件管理器安裝 IronPDF 庫

使用開發者命令提示符

透過開發者命令提示字元安裝IronPDF NuGet 套件

  • 開啟開發者命令提示符
  • 輸入以下命令:

    nuget install IronPdf
    nuget install IronPdf
    SHELL
  • 按回車鍵
  • 該軟體包會下載並安裝
  • 重新載入 Visual Studio 項目

直接下載 NuGet 套件

直接從 NuGet 下載並安裝 IronPDF:

  • 前往IronPdf NuGet 頁面
  • 選擇下載包 按兩下下載的軟體包 該軟體包用於安裝
  • 重新載入 Visual Studio 項目

透過下載庫檔案來安裝 IronPDF。

直接從IronPDF 下載頁面下載 IronPDF .DLL 檔案。

IronPDF website homepage showing the C# PDF Library with download options for DLL and NuGet installation

圖 4.從 IronPDF 網站下載 IronPDF 庫 DLL

在項目中引用該庫:

  • 在解決方案資源管理器中以滑鼠右鍵按一下解決方案。
  • 選擇參考文獻
  • 瀏覽 IronPDF.dll 庫 按一下"確定"

IronPDF現在可以使用了。 接下來我們安裝 XFINIUM.PDF。

如何安裝 XFINIUM.PDF?

在 .NET Core 中,將 Xfinium PDF 安裝為 CakePHP 外掛程式或工具:

# Install Xfinium.Pdf.NetCore as a Cake Addin
#addin nuget:?package=Xfinium.Pdf.NetCore&version=10.2.0
# Install Xfinium.Pdf.NetCore as a Cake Addin
#addin nuget:?package=Xfinium.Pdf.NetCore&version=10.2.0
SHELL
# Install Xfinium.Pdf.NetCore as a Cake Tool
#tool nuget:?package=Xfinium.Pdf.NetCore&version=10.2.0
# Install Xfinium.Pdf.NetCore as a Cake Tool
#tool nuget:?package=Xfinium.Pdf.NetCore&version=10.2.0
SHELL

現在讓我們來比較一下 IronPDF 和 XFINIUM.PDF。

如何在.NET Core中建立簡單的PDF文件?

軟體開發人員必須知道如何使用 C#動態建立 PDF 檔案。 您可能需要建立 PDF 文件,例如根據使用者輸入生成報告、將使用者文字儲存為 PDF、提取 HTML 資訊並將其轉換為 PDF等等。

這兩個庫都可以將HTML網頁轉換為PDF 。 讓我們逐一分析每個庫的方法。

使用 IronPDF

IronPDF 提供了多種建立 PDF 文件的方法。

現有 PDF 鏈接

IronPDF 可以輕鬆地從現有 URL 將 HTML 轉換為 PDF 文件。 完全支援JavaScript圖片、表單和 CSS。

此實作會自動處理 URL 渲染:

// Create an instance of the ChromePdfRenderer
IronPdf.ChromePdfRenderer Renderer = new IronPdf.ChromePdfRenderer();

// Configure rendering options for better performance
Renderer.RenderingOptions.WaitFor.RenderDelay = 500; // Wait for JavaScript to load
Renderer.RenderingOptions.CssMediaType = IronPdf.Rendering.PdfCssMediaType.Print;

// Render a URL to PDF
using var Pdf = Renderer.RenderUrlAsPdf("___PROTECTED_URL_134___");

// Save the PDF with metadata
Pdf.MetaData.Author = "IronPDF";
Pdf.MetaData.Title = "Website to PDF Conversion";
Pdf.SaveAs("url.pdf");
// Create an instance of the ChromePdfRenderer
IronPdf.ChromePdfRenderer Renderer = new IronPdf.ChromePdfRenderer();

// Configure rendering options for better performance
Renderer.RenderingOptions.WaitFor.RenderDelay = 500; // Wait for JavaScript to load
Renderer.RenderingOptions.CssMediaType = IronPdf.Rendering.PdfCssMediaType.Print;

// Render a URL to PDF
using var Pdf = Renderer.RenderUrlAsPdf("___PROTECTED_URL_134___");

// Save the PDF with metadata
Pdf.MetaData.Author = "IronPDF";
Pdf.MetaData.Title = "Website to PDF Conversion";
Pdf.SaveAs("url.pdf");
$vbLabelText   $csharpLabel

將 HTML 輸入字串轉換為 PDF

請看以下程式碼範例,該範例用於從 HTML 字串渲染 PDF 頁面。 你可以單獨使用 HTML,也可以與 CSS、圖片和 JavaScript 結合使用:

// Create an instance of the ChromePdfRenderer
var Renderer = new IronPdf.ChromePdfRenderer();

// Configure rendering options
Renderer.RenderingOptions.MarginTop = 50; // millimeters
Renderer.RenderingOptions.MarginBottom = 50;
Renderer.RenderingOptions.CssMediaType = IronPdf.Rendering.PdfCssMediaType.Print;

// Render a simple HTML string to PDF
using var PDF = Renderer.RenderHtmlAsPdf("<h1>Html with CSS and Images</h1>");

// Add document properties
PDF.MetaData.Author = "Development Team";
PDF.MetaData.Keywords = "HTML, PDF, C#";
PDF.MetaData.ModifiedDate = DateTime.Now;

// Save the PDF
PDF.SaveAs("pixel-perfect.pdf");

// Load external HTML assets: images, CSS, and javascript
// An optional BasePath 'C:\site\assets\' is set as the file location to load assets from 
using var AdvancedPDF = Renderer.RenderHtmlAsPdf("<img src='icons/iron.png'>", @"C:\site\assets\");

// Apply security settings
AdvancedPDF.Password = "pass123";
AdvancedPDF.SecuritySettings.AllowUserPrinting = IronPdf.Security.PdfPrintSecurity.FullPrintRights;

// Save the advanced PDF with external assets
AdvancedPDF.SaveAs("html-with-assets.pdf");
// Create an instance of the ChromePdfRenderer
var Renderer = new IronPdf.ChromePdfRenderer();

// Configure rendering options
Renderer.RenderingOptions.MarginTop = 50; // millimeters
Renderer.RenderingOptions.MarginBottom = 50;
Renderer.RenderingOptions.CssMediaType = IronPdf.Rendering.PdfCssMediaType.Print;

// Render a simple HTML string to PDF
using var PDF = Renderer.RenderHtmlAsPdf("<h1>Html with CSS and Images</h1>");

// Add document properties
PDF.MetaData.Author = "Development Team";
PDF.MetaData.Keywords = "HTML, PDF, C#";
PDF.MetaData.ModifiedDate = DateTime.Now;

// Save the PDF
PDF.SaveAs("pixel-perfect.pdf");

// Load external HTML assets: images, CSS, and javascript
// An optional BasePath 'C:\site\assets\' is set as the file location to load assets from 
using var AdvancedPDF = Renderer.RenderHtmlAsPdf("<img src='icons/iron.png'>", @"C:\site\assets\");

// Apply security settings
AdvancedPDF.Password = "pass123";
AdvancedPDF.SecuritySettings.AllowUserPrinting = IronPdf.Security.PdfPrintSecurity.FullPrintRights;

// Save the advanced PDF with external assets
AdvancedPDF.SaveAs("html-with-assets.pdf");
$vbLabelText   $csharpLabel

有關更進階的 HTML 轉 PDF 轉換技巧,請參閱HTML 轉 PDF 教學

使用 XFINIUM.PDF

使用 XFINIUM.PDF 建立空白 PDF 文件只需三行程式碼:建立文件、建立頁面、儲存:

// Create a new PDF document
PdfFixedDocument document = new PdfFixedDocument();

// Add a page to the document
PdfPage page = document.Pages.Add();

// Save the document as a PDF file
document.Save("empty.pdf");
// Create a new PDF document
PdfFixedDocument document = new PdfFixedDocument();

// Add a page to the document
PdfPage page = document.Pages.Add();

// Save the document as a PDF file
document.Save("empty.pdf");
$vbLabelText   $csharpLabel

新增文字內容需要三行額外的程式碼:建立字體、建立顏色畫筆和繪製文字:

// Create a new PDF document
PdfFixedDocument document = new PdfFixedDocument();
PdfPage page = document.Pages.Add();

// Create a standard font with Helvetica face and 24 point size
PdfStandardFont helvetica = new PdfStandardFont(PdfStandardFontFace.Helvetica, 24);

// Create a solid RGB red brush.
PdfBrush brush = new PdfBrush(PdfRgbColor.Red);

// Draw the text on the page.
page.Graphics.DrawString("Hello World", helvetica, brush, 100, 100);

// Save the document as a PDF file
document.Save("helloworld.pdf");
// Create a new PDF document
PdfFixedDocument document = new PdfFixedDocument();
PdfPage page = document.Pages.Add();

// Create a standard font with Helvetica face and 24 point size
PdfStandardFont helvetica = new PdfStandardFont(PdfStandardFontFace.Helvetica, 24);

// Create a solid RGB red brush.
PdfBrush brush = new PdfBrush(PdfRgbColor.Red);

// Draw the text on the page.
page.Graphics.DrawString("Hello World", helvetica, brush, 100, 100);

// Save the document as a PDF file
document.Save("helloworld.pdf");
$vbLabelText   $csharpLabel

此物件模型與 PDF 標準非常相似。 這種方法在建構複雜抽象概念(例如流程文件)方面具有明顯的優勢。 ## 如何建立可填寫 PDF 文件

使用 XFINIUM.PDF

XFINIUM.PDF 允許您建立新的 PDF 表單填寫現有的 PDF 表單

每種 PDF 表單欄位類型都有一個對應的類別:

  • PdfTextBoxField – 文字方塊字段
  • PdfCheckBoxField – 複選框
  • PdfRadioButtonField – 單選按鈕集
  • PdfComboboxField – 組合框
  • PdfListboxField – 列錶框
  • PdfPushbuttonField – 按鈕
  • PdfSignatureField – 簽名字段

若要建立表單字段,請指定字段名稱和頁面位置。 建立欄位物件後,將其新增至頁面並設定其屬性:

// Create a text box field named "firstname"
PdfTextBoxField firstNameTextBox = new PdfTextBoxField("firstname");

// Add the field to a PDF page
pdfpage.Fields.Add(firstNameTextBox);

// Set the position of the field on the PDF page
firstNameTextBox.Widgets[0].VisualRectangle = new PdfVisualRectangle(150, 45, 200, 20);
// Create a text box field named "firstname"
PdfTextBoxField firstNameTextBox = new PdfTextBoxField("firstname");

// Add the field to a PDF page
pdfpage.Fields.Add(firstNameTextBox);

// Set the position of the field on the PDF page
firstNameTextBox.Widgets[0].VisualRectangle = new PdfVisualRectangle(150, 45, 200, 20);
$vbLabelText   $csharpLabel

若要填寫現有的 PDF 表單,請將其載入到PdfFixedDocument物件中。 文件的欄位集合會自動填入。 您可以按索引或名稱查找字段,並透過設定值屬性來填充它們:

// Load an existing PDF document with forms
PdfFixedDocument document = new PdfFixedDocument("form.pdf");

// Fill form fields with values
(document.Form.Fields["firstname"] as PdfTextBoxField).Text = "John";
(document.Form.Fields["lastname"] as PdfTextBoxField).Value = "Doe";
(document.Form.Fields["sex"].Widgets[0] as PdfRadioButtonWidget).Checked = true;
(document.Form.Fields["firstcar"] as PdfComboBoxField).SelectedIndex = 0;
(document.Form.Fields["secondcar"] as PdfListBoxField).SelectedIndex = 1;
(document.Form.Fields["agree"] as PdfCheckBoxField).Checked = true;

// Save the filled form as a new PDF file
document.Save("form_filled.pdf");
// Load an existing PDF document with forms
PdfFixedDocument document = new PdfFixedDocument("form.pdf");

// Fill form fields with values
(document.Form.Fields["firstname"] as PdfTextBoxField).Text = "John";
(document.Form.Fields["lastname"] as PdfTextBoxField).Value = "Doe";
(document.Form.Fields["sex"].Widgets[0] as PdfRadioButtonWidget).Checked = true;
(document.Form.Fields["firstcar"] as PdfComboBoxField).SelectedIndex = 0;
(document.Form.Fields["secondcar"] as PdfListBoxField).SelectedIndex = 1;
(document.Form.Fields["agree"] as PdfCheckBoxField).Checked = true;

// Save the filled form as a new PDF file
document.Save("form_filled.pdf");
$vbLabelText   $csharpLabel

使用 IronPDF

以下是如何使用 IronPDF建立可填寫 PDF 的方法:

// PM> Install-Package IronPdf
using IronPdf;
using IronPdf.Rendering;

// Step 1. Creating a PDF with editable forms from HTML using form and input tags
var FormHtml = @"
<html>
    <head>
        <style>
            body { font-family: Arial, sans-serif; margin: 40px; }
            h2 { color: #333; }
            form { background: #f4f4f4; padding: 20px; border-radius: 8px; }
            input[type='text'] { 
                width: 100%; 
                padding: 8px; 
                margin: 10px 0;
                border: 1px solid #ddd;
                border-radius: 4px;
            }
            input[type='checkbox'] { margin-right: 10px; }
            select { width: 100%; padding: 8px; margin: 10px 0; }
        </style>
    </head>
    <body>
        <h2>Editable PDF Form</h2>
        <form>
          First name:<br> <input type='text' name='firstname' value=''> <br>
          Last name:<br> <input type='text' name='lastname' value=''>
          <br><br>
          Email:<br> <input type='text' name='email' value=''>
          <br><br>
          Subscribe to newsletter: <input type='checkbox' name='newsletter' value='yes'>
          <br><br>
          Country: 
          <select name='country'>
              <option value='usa'>United States</option>
              <option value='uk'>United Kingdom</option>
              <option value='canada'>Canada</option>
          </select>
        </form>
    </body>
</html>";

// Create a PDF renderer with form creation enabled
IronPdf.ChromePdfRenderer Renderer = new IronPdf.ChromePdfRenderer();
Renderer.RenderingOptions.CreatePdfFormsFromHtml = true;
Renderer.RenderingOptions.CssMediaType = PdfCssMediaType.Print;
Renderer.RenderingOptions.MarginTop = 20;
Renderer.RenderingOptions.MarginBottom = 20;

// Render the HTML as a PDF and save it
var pdfDocument = Renderer.RenderHtmlAsPdf(FormHtml);
pdfDocument.SaveAs("BasicForm.pdf");

// Step 2. Reading and Writing PDF form values.
var FormDocument = PdfDocument.FromFile("BasicForm.pdf");

// Get form field collection
var form = FormDocument.Form;

// Set and Read the value of the "firstname" field
var FirstNameField = form.FindFormField("firstname");
FirstNameField.Value = "Minnie";
Console.WriteLine("FirstNameField value: {0}", FirstNameField.Value);

// Set and Read the value of the "lastname" field
var LastNameField = form.FindFormField("lastname");
LastNameField.Value = "Mouse";
Console.WriteLine("LastNameField value: {0}", LastNameField.Value);

// Set email field
var EmailField = form.FindFormField("email");
EmailField.Value = "minnie.mouse@example.com";

// Set checkbox
var NewsletterField = form.FindFormField("newsletter");
NewsletterField.Value = "yes";

// Set dropdown selection
var CountryField = form.FindFormField("country");
CountryField.Value = "usa";

// Save the form with filled values
FormDocument.SaveAs("FilledForm.pdf");

// Step 3. Flattening the form (making it non-editable)
FormDocument.Form.Flatten();
FormDocument.SaveAs("FlattenedForm.pdf");
// PM> Install-Package IronPdf
using IronPdf;
using IronPdf.Rendering;

// Step 1. Creating a PDF with editable forms from HTML using form and input tags
var FormHtml = @"
<html>
    <head>
        <style>
            body { font-family: Arial, sans-serif; margin: 40px; }
            h2 { color: #333; }
            form { background: #f4f4f4; padding: 20px; border-radius: 8px; }
            input[type='text'] { 
                width: 100%; 
                padding: 8px; 
                margin: 10px 0;
                border: 1px solid #ddd;
                border-radius: 4px;
            }
            input[type='checkbox'] { margin-right: 10px; }
            select { width: 100%; padding: 8px; margin: 10px 0; }
        </style>
    </head>
    <body>
        <h2>Editable PDF Form</h2>
        <form>
          First name:<br> <input type='text' name='firstname' value=''> <br>
          Last name:<br> <input type='text' name='lastname' value=''>
          <br><br>
          Email:<br> <input type='text' name='email' value=''>
          <br><br>
          Subscribe to newsletter: <input type='checkbox' name='newsletter' value='yes'>
          <br><br>
          Country: 
          <select name='country'>
              <option value='usa'>United States</option>
              <option value='uk'>United Kingdom</option>
              <option value='canada'>Canada</option>
          </select>
        </form>
    </body>
</html>";

// Create a PDF renderer with form creation enabled
IronPdf.ChromePdfRenderer Renderer = new IronPdf.ChromePdfRenderer();
Renderer.RenderingOptions.CreatePdfFormsFromHtml = true;
Renderer.RenderingOptions.CssMediaType = PdfCssMediaType.Print;
Renderer.RenderingOptions.MarginTop = 20;
Renderer.RenderingOptions.MarginBottom = 20;

// Render the HTML as a PDF and save it
var pdfDocument = Renderer.RenderHtmlAsPdf(FormHtml);
pdfDocument.SaveAs("BasicForm.pdf");

// Step 2. Reading and Writing PDF form values.
var FormDocument = PdfDocument.FromFile("BasicForm.pdf");

// Get form field collection
var form = FormDocument.Form;

// Set and Read the value of the "firstname" field
var FirstNameField = form.FindFormField("firstname");
FirstNameField.Value = "Minnie";
Console.WriteLine("FirstNameField value: {0}", FirstNameField.Value);

// Set and Read the value of the "lastname" field
var LastNameField = form.FindFormField("lastname");
LastNameField.Value = "Mouse";
Console.WriteLine("LastNameField value: {0}", LastNameField.Value);

// Set email field
var EmailField = form.FindFormField("email");
EmailField.Value = "minnie.mouse@example.com";

// Set checkbox
var NewsletterField = form.FindFormField("newsletter");
NewsletterField.Value = "yes";

// Set dropdown selection
var CountryField = form.FindFormField("country");
CountryField.Value = "usa";

// Save the form with filled values
FormDocument.SaveAs("FilledForm.pdf");

// Step 3. Flattening the form (making it non-editable)
FormDocument.Form.Flatten();
FormDocument.SaveAs("FlattenedForm.pdf");
$vbLabelText   $csharpLabel

首先,您需要建立一個包含 HTML 格式標籤的表單。 該庫可以處理儲存為 PDF 時的複雜情況。 表單值的讀取和寫入是透過FindFormField函數完成的。 您的應用程式可以立即使用此功能以程式設計方式填寫表單。

有關高級表單處理(包括數位簽章)的信息,請參閱"建立 PDF 表單"教學

如何對 PDF 文件進行數位簽名

遠距辦公需要高效率的文件處理能力。 填寫和簽署表格、發送文件、處理文件是日常業務活動。 使用 PDF 文件、資料夾和表格進行簽名可以取代紙本文件。 數位簽名使公司能夠在線上簽署協議和共享 PDF 表格。

使用 XFINIUM.PDF

簽章域用於在 PDF 檔案中應用數位簽章( PdfSignatureField類別)。 雖然簽章欄只出現在一頁上,但數位簽章會對整個文件進行簽章。

簽名過程使用PdfDigitalSignature物件來設定簽名屬性。 簽名是在根據 PDF 文件的二進位佈局保存文件時產生的。

PdfDigitalSignature為所有 XFINIUM 簽名提供基礎:

  • PdfCmsDigitalSignature – CMS 標準簽名(繼承自PdfDigitalSignature
  • PdfPadesDigitalSignature – PADES 標準簽名(繼承自PdfCmsDigitalSignature
  • PdfInteractiveCmsDigitalSignature – 使用硬體智慧卡的CMS 簽名
  • PdfInteractivePadesDigitalSignature – 支援硬體智慧卡的 PADES
  • PdfDocumentTimeStamp – 文件級時間戳記(繼承自PdfDigitalSignature

使用 IronPDF

開發人員經常詢問如何使用 IronPDF 和 C# 以程式設計方式為 PDF 新增簽名。 這可能意味著:

  • 從檔案中新增圖形簽名圖像 -採用加密簽章以防止竄改
  • 添加帶有加密簽名的手寫簽名圖標

第一種方法是將簽名 PNG 圖片新增到現有的 PDF 頁面上。 可用於簽名或公司印章:

// Open an existing PDF document or create a new one
var Pdf = PdfDocument.FromFile(@"C:\Path\To\ASPX to PDF.pdf");

// Define an HTML stamp with a signature image
var SignatureStamp = new HtmlStamp()
{
    Html = "<img src='signature.png' />",
    Width = 150,
    Height = 50,
    Bottom = 300,
    Left = 85,
    ZIndex = HtmlStamp.StampLayer.OnTopOfExistingPDFContent
};

// Advanced stamp with styling
var StyledSignatureStamp = new HtmlStamp()
{
    Html = @"<div style='border: 2px solid #000; padding: 10px; background: rgba(255,255,255,0.9);'>
                <img src='signature.png' style='width: 120px;' />
                <p style='margin: 5px 0 0 0; font-size: 10px;'>Digitally Signed</p>
                <p style='margin: 0; font-size: 8px;'>{date}</p>
             </div>",
    Width = 150,
    Height = 100,
    Bottom = 50,
    Right = 50,
    ZIndex = HtmlStamp.StampLayer.OnTopOfExistingPDFContent
};

// Stamp the signature on the first page of the PDF
Pdf.StampHTML(SignatureStamp, 1);

// Or apply to all pages
Pdf.StampHTML(StyledSignatureStamp);

// Save the stamped PDF
Pdf.SaveAs(@"C:\Path\To\Stamped_PDF.pdf");
// Open an existing PDF document or create a new one
var Pdf = PdfDocument.FromFile(@"C:\Path\To\ASPX to PDF.pdf");

// Define an HTML stamp with a signature image
var SignatureStamp = new HtmlStamp()
{
    Html = "<img src='signature.png' />",
    Width = 150,
    Height = 50,
    Bottom = 300,
    Left = 85,
    ZIndex = HtmlStamp.StampLayer.OnTopOfExistingPDFContent
};

// Advanced stamp with styling
var StyledSignatureStamp = new HtmlStamp()
{
    Html = @"<div style='border: 2px solid #000; padding: 10px; background: rgba(255,255,255,0.9);'>
                <img src='signature.png' style='width: 120px;' />
                <p style='margin: 5px 0 0 0; font-size: 10px;'>Digitally Signed</p>
                <p style='margin: 0; font-size: 8px;'>{date}</p>
             </div>",
    Width = 150,
    Height = 100,
    Bottom = 50,
    Right = 50,
    ZIndex = HtmlStamp.StampLayer.OnTopOfExistingPDFContent
};

// Stamp the signature on the first page of the PDF
Pdf.StampHTML(SignatureStamp, 1);

// Or apply to all pages
Pdf.StampHTML(StyledSignatureStamp);

// Save the stamped PDF
Pdf.SaveAs(@"C:\Path\To\Stamped_PDF.pdf");
$vbLabelText   $csharpLabel

使用一行程式碼,透過 .pfx 和 .p12 X509Certificate2 數位憑證對PDF 檔案進行加密簽署

// 123456 below represents the signature password
new IronPdf.PdfSignature("CertificateFile.p12", "123456").SignPdfFile("ASPX to PDF.pdf");

// Or with more control
var signature = new IronPdf.PdfSignature("CertificateFile.p12", "123456")
{
    SigningContact = "john@example.com",
    SigningLocation = "New York, USA",
    SigningReason = "Contract Agreement"
};

// Load the PDF
var pdf = PdfDocument.FromFile("contract.pdf");

// Sign and save
pdf.SignPdfWithDigitalSignature(signature);
pdf.SaveAs("signed-contract.pdf");
// 123456 below represents the signature password
new IronPdf.PdfSignature("CertificateFile.p12", "123456").SignPdfFile("ASPX to PDF.pdf");

// Or with more control
var signature = new IronPdf.PdfSignature("CertificateFile.p12", "123456")
{
    SigningContact = "john@example.com",
    SigningLocation = "New York, USA",
    SigningReason = "Contract Agreement"
};

// Load the PDF
var pdf = PdfDocument.FromFile("contract.pdf");

// Sign and save
pdf.SignPdfWithDigitalSignature(signature);
pdf.SaveAs("signed-contract.pdf");
$vbLabelText   $csharpLabel

這個進階範例將 .pfx / .p12 X509Certificate2 數位 ID 簽章與手寫簽章結合:

// Create a digital signature using a certificate file
var Signature = new IronPdf.PdfSignature("Iron.pfx", "123456");

// Render a PDF document to be signed
var Renderer = new ChromePdfRenderer();
Renderer.RenderingOptions.MarginBottom = 0;
Renderer.RenderingOptions.MarginTop = 0;
Renderer.RenderingOptions.EnableJavaScript = true;
Renderer.RenderingOptions.CssMediaType = IronPdf.Rendering.PdfCssMediaType.Print;

// Create PDF with security features
string html = @"<h1>Contract Agreement</h1>
                <p>This document is digitally signed and encrypted.</p>
                <p>Agreement Date: " + DateTime.Now.ToString("yyyy-MM-dd") + @"</p>";

PdfDocument doc = Renderer.RenderHtmlAsPdf(html);

// Configure optional signing options and a handwritten signature graphic
Signature.SigningContact = "support@ironsoftware.com";
Signature.SigningLocation = "Chicago, USA";
Signature.SigningReason = "To show how to sign a PDF";

// Load a handwritten signature image
Signature.LoadSignatureImageFromFile("handwriting.png");

// Advanced security: Set permissions
doc.SecuritySettings.AllowUserPrinting = IronPdf.Security.PdfPrintSecurity.NoPrint;
doc.SecuritySettings.AllowUserEdits = IronPdf.Security.PdfEditSecurity.NoEdit;
doc.SecuritySettings.AllowUserCopyPasteContent = false;

// Sign the PDF document with the digital signature
doc.SignPdfWithDigitalSignature(Signature);

// Add password protection
doc.Password = "userpassword";
doc.OwnerPassword = "ownerpassword";

// Save the signed PDF document
doc.SaveAs("Signed_ASPX_to_PDF.pdf");
// Create a digital signature using a certificate file
var Signature = new IronPdf.PdfSignature("Iron.pfx", "123456");

// Render a PDF document to be signed
var Renderer = new ChromePdfRenderer();
Renderer.RenderingOptions.MarginBottom = 0;
Renderer.RenderingOptions.MarginTop = 0;
Renderer.RenderingOptions.EnableJavaScript = true;
Renderer.RenderingOptions.CssMediaType = IronPdf.Rendering.PdfCssMediaType.Print;

// Create PDF with security features
string html = @"<h1>Contract Agreement</h1>
                <p>This document is digitally signed and encrypted.</p>
                <p>Agreement Date: " + DateTime.Now.ToString("yyyy-MM-dd") + @"</p>";

PdfDocument doc = Renderer.RenderHtmlAsPdf(html);

// Configure optional signing options and a handwritten signature graphic
Signature.SigningContact = "support@ironsoftware.com";
Signature.SigningLocation = "Chicago, USA";
Signature.SigningReason = "To show how to sign a PDF";

// Load a handwritten signature image
Signature.LoadSignatureImageFromFile("handwriting.png");

// Advanced security: Set permissions
doc.SecuritySettings.AllowUserPrinting = IronPdf.Security.PdfPrintSecurity.NoPrint;
doc.SecuritySettings.AllowUserEdits = IronPdf.Security.PdfEditSecurity.NoEdit;
doc.SecuritySettings.AllowUserCopyPasteContent = false;

// Sign the PDF document with the digital signature
doc.SignPdfWithDigitalSignature(Signature);

// Add password protection
doc.Password = "userpassword";
doc.OwnerPassword = "ownerpassword";

// Save the signed PDF document
doc.SaveAs("Signed_ASPX_to_PDF.pdf");
$vbLabelText   $csharpLabel

要了解完整的安全實現,請查閱Ironsecuredoc 文檔,以了解高級文檔保護功能。 ## 各個函式庫如何處理現代 CSS 框架和 Bootstrap?

現代 Web 應用程式通常依賴 Bootstrap 等 CSS 框架來實現快速 UI 開發和響應式設計。 PDF 產生工具必須準確地保留這些框架佈局,以確保文件的專業品質。

IronPDF:完全支援 Bootstrap 框架

IronPDF 的 Chromium 渲染引擎完全支援現代 CSS 框架:

  • Bootstrap 5:完全支援 Flexbox 和 CSS Grid 渲染,以及所有響應式元件
  • Bootstrap 4:完整的卡片系統、導覽列和實用類
  • Tailwind CSS:所有實用性優先的類別及其響應式變體
  • Foundation 和其他框架:完全支援 CSS3,這意味著所有現代框架都能正常運作。 -進階 CSS: Flexbox、CSS Grid、自訂屬性、動畫和變換

實際驗證:Bootstrap 首頁和範本能夠以瀏覽器精確的保真度進行轉換。

程式碼範例:使用 Bootstrap Cards 進行活動行程安排

using IronPdf;

var renderer = new ChromePdfRenderer();

// Configure rendering for optimal Bootstrap output
renderer.RenderingOptions.CssMediaType = IronPdf.Rendering.PdfCssMediaType.Print;
renderer.RenderingOptions.EnableJavaScript = true;
renderer.RenderingOptions.RenderDelay = 500; // Allow JS to fully load
renderer.RenderingOptions.ViewPortWidth = 1280; // Desktop viewport
renderer.RenderingOptions.MarginTop = 10;
renderer.RenderingOptions.MarginBottom = 10;
renderer.RenderingOptions.MarginLeft = 10;
renderer.RenderingOptions.MarginRight = 10;

string bootstrapSchedule = @"
<!DOCTYPE html>
<html>
<head>
    <link href='___PROTECTED_URL_135___ rel='stylesheet'>
    <style>
        @media print {
            .pagebreak { page-break-after: always; }
        }
    </style>
</head>
<body>
    <div class='container my-5'>
        <h1 class='text-center mb-5'>Tech Conference 2025 - Schedule</h1>

        <div class='row g-4'>
            <div class='col-md-6'>
                <div class='card border-primary'>
                    <div class='card-header bg-primary text-white d-flex justify-content-between align-items-center'>
                        <h5 class='mb-0'>Keynote Session</h5>
                        <span class='badge bg-light text-primary'>9:00 AM</span>
                    </div>
                    <div class='card-body'>
                        <h6 class='card-subtitle mb-2 text-muted'>Main Auditorium</h6>
                        <p class='card-text'><strong>The Future of AI in Software Development</strong></p>
                        <p class='card-text'>Join us for an exploration of how artificial intelligence is transforming the software development environment.</p>
                        <div class='d-flex align-items-center'>
                            <img src='___PROTECTED_URL_136___ class='rounded-circle me-2' alt='Speaker'>
                            <div>
                                <div class='fw-bold'>Dr. Sarah Chen</div>
                                <small class='text-muted'>AI Research Lead</small>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <div class='col-md-6'>
                <div class='card border-success'>
                    <div class='card-header bg-success text-white d-flex justify-content-between align-items-center'>
                        <h5 class='mb-0'>Workshop</h5>
                        <span class='badge bg-light text-success'>10:30 AM</span>
                    </div>
                    <div class='card-body'>
                        <h6 class='card-subtitle mb-2 text-muted'>Workshop Room A</h6>
                        <p class='card-text'><strong>Hands-On: Cloud-Native Architecture</strong></p>
                        <p class='card-text'>Learn practical techniques for building flexible, cloud-native applications with modern frameworks.</p>
                        <div class='d-flex align-items-center'>
                            <img src='___PROTECTED_URL_137___ class='rounded-circle me-2' alt='Speaker'>
                            <div>
                                <div class='fw-bold'>Michael Rodriguez</div>
                                <small class='text-muted'>Cloud Architect</small>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <div class='col-md-6'>
                <div class='card border-warning'>
                    <div class='card-header bg-warning text-dark d-flex justify-content-between align-items-center'>
                        <h5 class='mb-0'>Panel Discussion</h5>
                        <span class='badge bg-dark'>2:00 PM</span>
                    </div>
                    <div class='card-body'>
                        <h6 class='card-subtitle mb-2 text-muted'>Main Auditorium</h6>
                        <p class='card-text'><strong>Security in Modern Web Applications</strong></p>
                        <p class='card-text'>Industry experts discuss current security challenges and best practices for protecting user data.</p>
                        <small class='text-muted'>Featuring 4 industry experts</small>
                    </div>
                </div>
            </div>

            <div class='col-md-6'>
                <div class='card border-info'>
                    <div class='card-header bg-info text-white d-flex justify-content-between align-items-center'>
                        <h5 class='mb-0'>Technical Talk</h5>
                        <span class='badge bg-light text-info'>3:30 PM</span>
                    </div>
                    <div class='card-body'>
                        <h6 class='card-subtitle mb-2 text-muted'>Room B</h6>
                        <p class='card-text'><strong>Performance Optimization Strategies</strong></p>
                        <p class='card-text'>Deep dive into advanced techniques for improve application performance and reducing latency.</p>
                        <div class='d-flex align-items-center'>
                            <img src='___PROTECTED_URL_138___ class='rounded-circle me-2' alt='Speaker'>
                            <div>
                                <div class='fw-bold'>Alex Kim</div>
                                <small class='text-muted'>Performance Engineer</small>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <div class='pagebreak'></div>

        <h2 class='mt-5'>Additional Sessions</h2>
        <div class='table-responsive'>
            <table class='table table-striped'>
                <thead>
                    <tr>
                        <th>Time</th>
                        <th>Session</th>
                        <th>Speaker</th>
                        <th>Location</th>
                    </tr>
                </thead>
                <tbody>
                    <tr>
                        <td>11:45 AM</td>
                        <td>Lightning Talks</td>
                        <td>Various</td>
                        <td>Room C</td>
                    </tr>
                    <tr>
                        <td>1:00 PM</td>
                        <td>Networking Lunch</td>
                        <td>-</td>
                        <td>Cafeteria</td>
                    </tr>
                </tbody>
            </table>
        </div>
    </div>
</body>
</html>";

// Generate the PDF
var pdf = renderer.RenderHtmlAsPdf(bootstrapSchedule);

// Add metadata
pdf.MetaData.Author = "Tech Conference Team";
pdf.MetaData.Title = "Conference Schedule 2025";
pdf.MetaData.Subject = "Event Schedule";

// Save the PDF
pdf.SaveAs("conference-schedule.pdf");

// Example: Generate responsive invoice with Bootstrap
string bootstrapInvoice = @"
<!DOCTYPE html>
<html>
<head>
    <link href='___PROTECTED_URL_139___ rel='stylesheet'>
    <link href='___PROTECTED_URL_140___ rel='stylesheet'>
</head>
<body>
    <div class='container mt-5'>
        <div class='row'>
            <div class='col-12'>
                <div class='card'>
                    <div class='card-body'>
                        <div class='row mb-4'>
                            <div class='col-sm-6'>
                                <h2 class='text-primary'><i class='fas fa-file-invoice'></i> INVOICE</h2>
                                <p class='mb-1'><strong>Invoice #:</strong> INV-2025-001</p>
                                <p class='mb-1'><strong>Date:</strong> " + DateTime.Now.ToString("MMMM dd, yyyy") + @"</p>
                            </div>
                            <div class='col-sm-6 text-sm-end'>
                                <h4>Your Company Name</h4>
                                <p class='mb-1'>123 Business St</p>
                                <p class='mb-1'>City, State 12345</p>
                                <p>contact@company.com</p>
                            </div>
                        </div>

                        <hr>

                        <div class='row mb-4'>
                            <div class='col-sm-6'>
                                <h5>Bill To:</h5>
                                <p class='mb-1'><strong>Client Company</strong></p>
                                <p class='mb-1'>456 Client Ave</p>
                                <p>City, State 67890</p>
                            </div>
                        </div>

                        <div class='table-responsive'>
                            <table class='table table-bordered'>
                                <thead class='table-primary'>
                                    <tr>
                                        <th>Description</th>
                                        <th class='text-center'>Quantity</th>
                                        <th class='text-end'>Price</th>
                                        <th class='text-end'>Total</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <tr>
                                        <td>Web Development Services</td>
                                        <td class='text-center'>40</td>
                                        <td class='text-end'>$150.00</td>
                                        <td class='text-end'>$6,000.00</td>
                                    </tr>
                                    <tr>
                                        <td>UI/UX Design</td>
                                        <td class='text-center'>20</td>
                                        <td class='text-end'>$125.00</td>
                                        <td class='text-end'>$2,500.00</td>
                                    </tr>
                                </tbody>
                                <tfoot>
                                    <tr>
                                        <td colspan='3' class='text-end'><strong>Subtotal:</strong></td>
                                        <td class='text-end'><strong>$8,500.00</strong></td>
                                    </tr>
                                    <tr>
                                        <td colspan='3' class='text-end'>Tax (10%):</td>
                                        <td class='text-end'>$850.00</td>
                                    </tr>
                                    <tr class='table-primary'>
                                        <td colspan='3' class='text-end'><strong>Total Due:</strong></td>
                                        <td class='text-end'><strong>$9,350.00</strong></td>
                                    </tr>
                                </tfoot>
                            </table>
                        </div>

                        <div class='alert alert-info mt-4'>
                            <i class='fas fa-info-circle'></i> Payment is due within 30 days. Thank you for your business!
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</body>
</html>";

var invoicePdf = renderer.RenderHtmlAsPdf(bootstrapInvoice);
invoicePdf.SaveAs("bootstrap-invoice.pdf");
using IronPdf;

var renderer = new ChromePdfRenderer();

// Configure rendering for optimal Bootstrap output
renderer.RenderingOptions.CssMediaType = IronPdf.Rendering.PdfCssMediaType.Print;
renderer.RenderingOptions.EnableJavaScript = true;
renderer.RenderingOptions.RenderDelay = 500; // Allow JS to fully load
renderer.RenderingOptions.ViewPortWidth = 1280; // Desktop viewport
renderer.RenderingOptions.MarginTop = 10;
renderer.RenderingOptions.MarginBottom = 10;
renderer.RenderingOptions.MarginLeft = 10;
renderer.RenderingOptions.MarginRight = 10;

string bootstrapSchedule = @"
<!DOCTYPE html>
<html>
<head>
    <link href='___PROTECTED_URL_135___ rel='stylesheet'>
    <style>
        @media print {
            .pagebreak { page-break-after: always; }
        }
    </style>
</head>
<body>
    <div class='container my-5'>
        <h1 class='text-center mb-5'>Tech Conference 2025 - Schedule</h1>

        <div class='row g-4'>
            <div class='col-md-6'>
                <div class='card border-primary'>
                    <div class='card-header bg-primary text-white d-flex justify-content-between align-items-center'>
                        <h5 class='mb-0'>Keynote Session</h5>
                        <span class='badge bg-light text-primary'>9:00 AM</span>
                    </div>
                    <div class='card-body'>
                        <h6 class='card-subtitle mb-2 text-muted'>Main Auditorium</h6>
                        <p class='card-text'><strong>The Future of AI in Software Development</strong></p>
                        <p class='card-text'>Join us for an exploration of how artificial intelligence is transforming the software development environment.</p>
                        <div class='d-flex align-items-center'>
                            <img src='___PROTECTED_URL_136___ class='rounded-circle me-2' alt='Speaker'>
                            <div>
                                <div class='fw-bold'>Dr. Sarah Chen</div>
                                <small class='text-muted'>AI Research Lead</small>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <div class='col-md-6'>
                <div class='card border-success'>
                    <div class='card-header bg-success text-white d-flex justify-content-between align-items-center'>
                        <h5 class='mb-0'>Workshop</h5>
                        <span class='badge bg-light text-success'>10:30 AM</span>
                    </div>
                    <div class='card-body'>
                        <h6 class='card-subtitle mb-2 text-muted'>Workshop Room A</h6>
                        <p class='card-text'><strong>Hands-On: Cloud-Native Architecture</strong></p>
                        <p class='card-text'>Learn practical techniques for building flexible, cloud-native applications with modern frameworks.</p>
                        <div class='d-flex align-items-center'>
                            <img src='___PROTECTED_URL_137___ class='rounded-circle me-2' alt='Speaker'>
                            <div>
                                <div class='fw-bold'>Michael Rodriguez</div>
                                <small class='text-muted'>Cloud Architect</small>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <div class='col-md-6'>
                <div class='card border-warning'>
                    <div class='card-header bg-warning text-dark d-flex justify-content-between align-items-center'>
                        <h5 class='mb-0'>Panel Discussion</h5>
                        <span class='badge bg-dark'>2:00 PM</span>
                    </div>
                    <div class='card-body'>
                        <h6 class='card-subtitle mb-2 text-muted'>Main Auditorium</h6>
                        <p class='card-text'><strong>Security in Modern Web Applications</strong></p>
                        <p class='card-text'>Industry experts discuss current security challenges and best practices for protecting user data.</p>
                        <small class='text-muted'>Featuring 4 industry experts</small>
                    </div>
                </div>
            </div>

            <div class='col-md-6'>
                <div class='card border-info'>
                    <div class='card-header bg-info text-white d-flex justify-content-between align-items-center'>
                        <h5 class='mb-0'>Technical Talk</h5>
                        <span class='badge bg-light text-info'>3:30 PM</span>
                    </div>
                    <div class='card-body'>
                        <h6 class='card-subtitle mb-2 text-muted'>Room B</h6>
                        <p class='card-text'><strong>Performance Optimization Strategies</strong></p>
                        <p class='card-text'>Deep dive into advanced techniques for improve application performance and reducing latency.</p>
                        <div class='d-flex align-items-center'>
                            <img src='___PROTECTED_URL_138___ class='rounded-circle me-2' alt='Speaker'>
                            <div>
                                <div class='fw-bold'>Alex Kim</div>
                                <small class='text-muted'>Performance Engineer</small>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <div class='pagebreak'></div>

        <h2 class='mt-5'>Additional Sessions</h2>
        <div class='table-responsive'>
            <table class='table table-striped'>
                <thead>
                    <tr>
                        <th>Time</th>
                        <th>Session</th>
                        <th>Speaker</th>
                        <th>Location</th>
                    </tr>
                </thead>
                <tbody>
                    <tr>
                        <td>11:45 AM</td>
                        <td>Lightning Talks</td>
                        <td>Various</td>
                        <td>Room C</td>
                    </tr>
                    <tr>
                        <td>1:00 PM</td>
                        <td>Networking Lunch</td>
                        <td>-</td>
                        <td>Cafeteria</td>
                    </tr>
                </tbody>
            </table>
        </div>
    </div>
</body>
</html>";

// Generate the PDF
var pdf = renderer.RenderHtmlAsPdf(bootstrapSchedule);

// Add metadata
pdf.MetaData.Author = "Tech Conference Team";
pdf.MetaData.Title = "Conference Schedule 2025";
pdf.MetaData.Subject = "Event Schedule";

// Save the PDF
pdf.SaveAs("conference-schedule.pdf");

// Example: Generate responsive invoice with Bootstrap
string bootstrapInvoice = @"
<!DOCTYPE html>
<html>
<head>
    <link href='___PROTECTED_URL_139___ rel='stylesheet'>
    <link href='___PROTECTED_URL_140___ rel='stylesheet'>
</head>
<body>
    <div class='container mt-5'>
        <div class='row'>
            <div class='col-12'>
                <div class='card'>
                    <div class='card-body'>
                        <div class='row mb-4'>
                            <div class='col-sm-6'>
                                <h2 class='text-primary'><i class='fas fa-file-invoice'></i> INVOICE</h2>
                                <p class='mb-1'><strong>Invoice #:</strong> INV-2025-001</p>
                                <p class='mb-1'><strong>Date:</strong> " + DateTime.Now.ToString("MMMM dd, yyyy") + @"</p>
                            </div>
                            <div class='col-sm-6 text-sm-end'>
                                <h4>Your Company Name</h4>
                                <p class='mb-1'>123 Business St</p>
                                <p class='mb-1'>City, State 12345</p>
                                <p>contact@company.com</p>
                            </div>
                        </div>

                        <hr>

                        <div class='row mb-4'>
                            <div class='col-sm-6'>
                                <h5>Bill To:</h5>
                                <p class='mb-1'><strong>Client Company</strong></p>
                                <p class='mb-1'>456 Client Ave</p>
                                <p>City, State 67890</p>
                            </div>
                        </div>

                        <div class='table-responsive'>
                            <table class='table table-bordered'>
                                <thead class='table-primary'>
                                    <tr>
                                        <th>Description</th>
                                        <th class='text-center'>Quantity</th>
                                        <th class='text-end'>Price</th>
                                        <th class='text-end'>Total</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <tr>
                                        <td>Web Development Services</td>
                                        <td class='text-center'>40</td>
                                        <td class='text-end'>$150.00</td>
                                        <td class='text-end'>$6,000.00</td>
                                    </tr>
                                    <tr>
                                        <td>UI/UX Design</td>
                                        <td class='text-center'>20</td>
                                        <td class='text-end'>$125.00</td>
                                        <td class='text-end'>$2,500.00</td>
                                    </tr>
                                </tbody>
                                <tfoot>
                                    <tr>
                                        <td colspan='3' class='text-end'><strong>Subtotal:</strong></td>
                                        <td class='text-end'><strong>$8,500.00</strong></td>
                                    </tr>
                                    <tr>
                                        <td colspan='3' class='text-end'>Tax (10%):</td>
                                        <td class='text-end'>$850.00</td>
                                    </tr>
                                    <tr class='table-primary'>
                                        <td colspan='3' class='text-end'><strong>Total Due:</strong></td>
                                        <td class='text-end'><strong>$9,350.00</strong></td>
                                    </tr>
                                </tfoot>
                            </table>
                        </div>

                        <div class='alert alert-info mt-4'>
                            <i class='fas fa-info-circle'></i> Payment is due within 30 days. Thank you for your business!
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</body>
</html>";

var invoicePdf = renderer.RenderHtmlAsPdf(bootstrapInvoice);
invoicePdf.SaveAs("bootstrap-invoice.pdf");
$vbLabelText   $csharpLabel

輸出:一個專業的會議日程表,採用 Bootstrap 的卡片網格、flexbox 對齊方式、徽章組件和響應式佈局——所有內容都準確地渲染在 PDF 中。

XFINIUM.PDF:HTML 和框架支援有限

XFINIUM.PDF 專注於 PDF 的產生和處理,而不是 HTML 到 PDF 的轉換。 該函式庫對 Bootstrap 和現代 CSS 框架有顯著限制:

-不支援原生 HTML 渲染: XFINIUM.PDF 不包含內建的 HTML 到 PDF 轉換引擎。 -僅支援基本 HTML:僅限於簡單的 HTML 結構,不支援進階 CSS -不支援 Bootstrap:不支援具有 flexbox 和 CSS Grid 的現代 Bootstrap 框架(4/5 版本)。 -需要採取變通方法:開發人員必須使用底層 PDF API 手動重新建立佈局。 -需要外部工具:可能需要與外部 HTML 渲染引擎集成

開發影響:使用 Bootstrap 或現代 CSS 框架的應用程式無法使用 XFINIUM.PDF 直接將其 UI 轉換為 PDF。 開發者必須:

  1. 使用 XFINIUM.PDF 的底層繪圖 API 重新建立佈局(需要大量開發時間)
  2. 整合外部 HTML 渲染工具(增加複雜性和依賴關係)
  3. 維護與 Web UI 並行的獨立 PDF 佈局程式碼(維護開銷)

對於需要使用現代框架將 HTML 轉換為 PDF 的項目,XFINIUM.PDF 的限制需要進行大量的額外開發。

如需了解 Bootstrap 和現代 CSS 框架的完整支持,請參閱 Bootstrap 和 Flexbox CSS 指南。

定價和授權方案有哪些?

XFINIUM.PDF 定價與許可

每個軟體包都有兩個版本:生成器版本用於 PDF 生成/編輯,檢視器版本包含所有生成器功能以及 PDF 渲染和檢視功能。

每個開發者都需要許可證。

  • 可免版稅分發至無限數量的桌上型/伺服器。
  • 協助訂閱包含一年的更新/支援服務。

價格範圍為每年 290.00 美元至 872.00 美元。

IronPDF定價和許可

IronPDF 可供開發使用,並可隨時授權用於商業用途。授權選項包括單一項目授權、單一開發者授權、代理商授權、跨國組織授權以及 SaaS/OEM 再分發授權。 所有許可證均包含 30 天退款保證、一年支援/升級、開發/測試/生產有效期以及永久許可證(一次性購買)。 Lite 套餐起價為$799 ,無任何經常性費用。

我應該選擇哪個PDF庫?

IronPDF庫簡化了PDF的創建過程,無需使用專有API。 "HTML-To-PDF"功能可以將HTML、JS、CSS、JPG、PNG、GIF和SVG等開放標準文件轉換為像素級完美的PDF檔案。 它建立在現有開發人員技能的基礎上。 您可以下載文件、透過電子郵件傳送或儲存到雲端,從而建立帳單、報價單、報告、合約和其他文書工作。 它可與 ASP.NET、ASP.NET Core、Web Forms、MVC、.NET Framework 和 .NET Core Web API 搭配使用。

XFINIUM.PDF 為初級和高級 PDF 開發人員提供功能。 無論您需要建立報告、填寫 PDF 表格、建立作品集、編輯信息,還是將 PDF 轉換為多頁 TIFF,它都能提供必要的工具。 基本物件模型遵循PDF規範。 程式碼無需修改即可在所有平台上編譯。

XFINIUM.PDF 許可證起價為 290 美元(產生器)和 387 美元(檢視器)版本。 IronPDF 的起價為$799 。 IronPDF 提供單一使用者和多使用者許可證,而 XFINIUM.PDF 則需要為每位開發人員購買許可證。 IronPDF 專業版授權(799 美元)支援無限用戶。

IronPDF 處理 PDF 檔案所需的程式碼行數比 XFINIUM.PDF 少,從而減輕了程式設計師的工作量。

Iron Software 提供全套軟體,只需點擊兩下即可使用。 目前,只需支付兩個庫的價格,即可獲得全部五個庫以及持續的支援。

請注意XFINIUM.PDF 是其各自所有者的註冊商標。 本網站與 XFINIUM.PDF 無任何關聯,亦未獲得其認可或贊助。 所有產品名稱、標誌和品牌均為其各自所有者的財產。 文中比較僅供參考,反映的是撰寫本文時可公開取得的資訊。

常見問題解答

IronPDF在HTML轉PDF轉換的主要特點是什麼?

IronPDF 利用 .NET Chromium 引擎將 HTML 轉換為 PDF。它支援 HTML5、CSS、JavaScript 和圖像集成,使其成為從 Web 內容創建 PDF 的全面解決方案。

XFINIUM.PDF 與其他 .NET 平台的 PDF 程式庫相比如何?

XFINIUM.PDF 是一個跨平台庫,提供生成器和檢視器兩個版本。它在 PDF 創建、編輯和渲染方面表現出色,並包含安全性、數位簽章和條碼支援等功能。

IronPDF 能否在 Azure 和 AWS 等雲端平台上使用?

是的,IronPDF 與包括 Azure 和 AWS 在內的各種平台相容,可在雲端環境中靈活部署 PDF 解決方案。

在 .NET 專案中,IronPDF 有哪些安裝選項?

IronPDF 可以透過 Visual Studio 的 NuGet 套件管理器、開發人員命令提示字元進行安裝,也可以直接下載 NuGet 套件或庫 DLL 進行安裝。

IronPDF有哪些PDF編輯功能?

IronPDF 提供強大的 PDF 編輯功能,包括填寫表單欄位、合併文件以及擷取文字和圖像。它還支援添加頁首、頁尾和註釋。

IronPDF 和 XFINIUM.PDF 的許可選項有何不同?

XFINIUM.PDF 提供起價為每位開發者 290 美元的授權許可,並允許免版稅分發。 IronPDF 提供更廣泛的授權選項,包括可供無限用戶使用的專業版授權。

XFINIUM.PDF 提供哪些安全功能?

XFINIUM.PDF 支援使用者和擁有者密碼、文件存取權限、RC4 和 AES 加密以及內容編輯等安全功能,以確保文件安全。

為什麼開發者會選擇 IronPDF 來進行專案開發?

開發者可能會選擇 IronPDF,因為它簡化了 PDF 操作方式,所需的程式碼行數更少,並且具有單一使用者和多使用者許可的靈活性。

IronPDF如何處理PDF中的表單填寫?

IronPDF 提供工具來填入 PDF 中的表單字段,從而實現動態文件建立和使用者互動。

這些PDF庫提供哪些數位簽章功能?

IronPDF 和 XFINIUM.PDF 都支援數位簽名,因此可以安全地驗證文件的真實性和完整性。

柯蒂斯·週
技術撰稿人

Curtis Chau擁有卡爾頓大學電腦科學學士學位,專長於前端開發,精通Node.js、TypeScript、JavaScript和React。他熱衷於打造直覺美觀的使用者介面,喜歡使用現代框架,並擅長撰寫結構清晰、視覺效果出色的使用者手冊。

除了開發工作之外,柯蒂斯對物聯網 (IoT) 也抱有濃厚的興趣,致力於探索硬體和軟體整合的創新方法。閒暇時,他喜歡玩遊戲和製作 Discord 機器人,將他對科技的熱愛與創造力結合。