跳至頁尾內容
產品對比

IronPDF 和 Apitron PDF 套件的比較

對於開發人員來說,在 C# 中處理 PDF 文件可能具有挑戰性。 創建這些文件的內容時需要考慮許多因素,而將不同格式的內容轉換為 PDF 時需要考慮的因素就更多了。 自動化如今在軟體開發過程中至關重要。 這些挑戰已透過開發旨在幫助讀取、寫入、建立和修改 PDF 文檔,以及編輯其屬性和將其從其他格式轉換的庫來解決。

這篇部落格文章比較了兩個適用於 .NET 和 .NET Core 的 PDF 程式庫:

IronPDF庫 Apitron PDF 套件

IronPDF 和 Apitron PDF Kit 是為 .NET 和 .NET Core 提供 PDF 操作功能的程式庫。 它們都可用於文件欄位轉換和操作任務。 它們還允許創建書籤。 下一步是決定哪個 C# PDF .NET 函式庫最適合我們的 .NET 專案。 本文將對這兩個PDF庫進行比較,幫助您做出選擇。

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

Apitron PDF 工具包庫及其功能

Apitron PDF Kit是一個 .NET 元件,它允許您以各種方式操作或轉換 PDF 檔案。 您可以新增圖片、圖畫和文字,簽署文件等等。 您也可以編輯現有內容。 Apitron PDF Kit .NET 元件可用於建立跨多個平台的行動、桌面、Web、Windows 和雲端應用程式。

使用此 PDF SDK,您將能夠:

  • 擷取、修改、新增圖形(文字、圖像、圖畫)
  • 拆分或合併 PDF 文檔
  • 填寫或建立受密碼保護的 PDF 表單,支援 FDF 格式
  • 建立具有可選內容群組 (OCG) 的多層 PDF 文檔
  • 在文件中新增或刪除字段
  • 使用從右到左或雙向文字建立頁面內容
  • 檢查文件中的資源 - 已定義的字體、嵌入的文件
  • 對 PDF 文件進行數位簽名並檢查現有簽名

IronPDF 的主要特點

開發人員,尤其是 C# 程式設計師,會非常欣賞 IronPDF .NET 函式庫。 透過此工具,您可以輕鬆建立 .NET Core PDF 處理應用程式。

IronPDF 使用 .NET Chromium 引擎將 HTML 頁面(程式碼或 URL 形式)轉換為 PDF 檔案。 無需使用複雜的 API 來定位導覽物件或從 HTML 設計 PDF。 IronPDF 支援標準 Web 文檔,包括 HTML、ASPX、JS、CSS 和圖片。

IronPDF 可以使用 HTML5、CSS、JS 和影像建立。 PDF檔案可以輕鬆編輯、新增印章以及新增頁首和頁尾。 它還使讀取 PDF 文字和提取圖形變得簡單易行。

IronPDF 的主要特色包括:

  • 使用 HTML4/5、CSS 和 JavaScript 建立 PDF 文檔
  • 載入帶有自訂網頁登入憑證、使用者代理程式、代理程式、cookie、HTTP 標頭和表單變數的 URL(啟用 HTML 登入表單後的登入)
  • 閱讀並填寫 PDF 表單字段
  • 從PDF文件中提取文字和圖形
  • 使用新的 HTML 內容更新 PDF 頁面
  • 建立基於文字或 HTML 的頁首和頁尾
  • 合併和分離 PDF 文件內容 將 ASP.NET Web 表單轉換為可列印的 PDF 文件 無需 Adobe Acrobat 軟體即可列印 PDF 文件

IronPDF幾乎可在所有與C#相容的作業系統和框架上運行,包括:

  • .NET Core 2.1、3.0、3.1、.NET 6 和 5
  • 符合 .NET Standard 2.0 通用相容性要求 Azure、AWS、Docker、Linux、Windows

文章其餘部分如下:

  1. IronPDF 安裝 2.Apitron PDF套件安裝
  2. 建立 PDF 文檔
  3. 在PDF中建立頁首和頁尾
  4. 對 PDF 檔案進行數位簽名
  5. 定價和許可

1. IronPDF 安裝

下載和安裝 IronPDF 庫有四種方法。 這些都是:

  1. 使用 NuGet 套件管理器
  2. 開發者命令提示符
  3. 直接下載 NuGet 套件
  4. 下載 IronPDF .DLL 函式庫

1.1. 使用 NuGet 套件管理器

要安裝 IronPDF,只需在解決方案資源管理器中右鍵單擊您的專案即可。 這將開啟 NuGet 套件管理器。

A Comparison of IronPDF with Apitron PDF SDK .NET - Figure 1: 使用解決方案資源管理器存取 NuGet 套件管理器。

使用解決方案資源管理器存取 NuGet 套件管理器。

選擇完成後,瀏覽並安裝 IronPDF 軟體包,如下圖所示。

A Comparison of IronPDF with Apitron PDF SDK .NET - Figure 2: 使用 NuGet 套件管理器安裝 IronPDF 庫

使用 NuGet 套件管理器安裝 IronPDF 庫

1.2. 使用開發者命令提示符

您也可以透過開發者命令提示字元安裝 IronPDF。

  • 開啟開發者命令提示字元--- 通常位於 Visual Studio 資料夾下
  • 輸入以下命令:
Install-Package IronPdf
  • 按回車鍵 這將下載並安裝該軟體包。
  • 重新載入專案並開始使用

1.3. 直接下載 NuGet 套件

也可以直接造訪IronPDF NuGet 套件網站並下載套件來安裝 IronPDF。 步驟如下:

  • 導覽至IronPDF NuGet 套件
  • 選擇下載包 按兩下下載的軟體包 軟體包將會安裝
  • 重新載入您的 Visual Studio 專案並開始使用。

IronPDF已下載完畢,可以使用了。 不過在此之前,我們應該先安裝 Apitron PDF 函式庫。

2.Apitron PDF套件安裝

對於 .NET Core 應用程序,我們可以使用 NuGet 套件管理器安裝 Apitron,或者我們可以直接從Apitron PDF Kit NuGet網站下載並安裝 Apitron。

  • 就像我們在 IronPDF 中一樣,在 Visual Studio 中開啟 NuGet 套件。
  • 搜尋 Apitron.PDF.Kit。
  • 在目前專案中點選安裝。
A Comparison of IronPDF with Apitron PDF SDK .NET - Figure 3: Apitron PDF 套件搜尋

Apitron PDF 套件搜尋

您也可以使用 NuGet 套件管理器控制台來安裝 Apitron。 請依照 IronPDF 中提到的"使用開發者命令提示字元"步驟操作,然後輸入以下命令:

Install-Package Apitron.PDF.Kit

按回車鍵。 它將下載並安裝 Apitron.PDF.Kit。

新增以下命名空間:

using Apitron.PDF.Kit;
using Apitron.PDF.Kit.FixedLayout.Resources;
using Apitron.PDF.Kit.FixedLayout.Resources.Fonts;
using Apitron.PDF.Kit.FlowLayout.Content;
using Apitron.PDF.Kit.Styles;
using Apitron.PDF.Kit.Styles.Appearance;
using Font = Apitron.PDF.Kit.Styles.Text.Font;
using Apitron.PDF.Kit;
using Apitron.PDF.Kit.FixedLayout.Resources;
using Apitron.PDF.Kit.FixedLayout.Resources.Fonts;
using Apitron.PDF.Kit.FlowLayout.Content;
using Apitron.PDF.Kit.Styles;
using Apitron.PDF.Kit.Styles.Appearance;
using Font = Apitron.PDF.Kit.Styles.Text.Font;
$vbLabelText   $csharpLabel

現在,讓我們來比較一下 IronPDF 和 Apitron PDF。

3. 建立 PDF 文檔

3.1. 使用 IronPDF

IronPDF 提供了多種建立 PDF 的方法。 讓我們來探討其中兩個重要的面向。

現有 PDF 鏈接

IronPDF 可以輕鬆地將任何 URL 轉換為 PDF。 以下程式碼有助於將 URL 轉換為 PDF。

var Renderer = new IronPdf.ChromePdfRenderer();
// Render a PDF from an existing URL
using var Pdf = Renderer.RenderUrlAsPdf("https://ironpdf.com/");
// Save the PDF to a file
Pdf.SaveAs("url.pdf");
var Renderer = new IronPdf.ChromePdfRenderer();
// Render a PDF from an existing URL
using var Pdf = Renderer.RenderUrlAsPdf("https://ironpdf.com/");
// Save the PDF to a file
Pdf.SaveAs("url.pdf");
$vbLabelText   $csharpLabel

將 HTML 輸入字串轉換為 PDF

以下程式碼說明如何根據 HTML 字串渲染 PDF 文件。 你可以只使用 HTML,也可以與 CSS、圖片和 JavaScript 結合使用。

var Renderer = new IronPdf.ChromePdfRenderer();
// Render a PDF from a simple HTML string
using var PDF = Renderer.RenderHtmlAsPdf("<h1>Html with CSS and Images</h1>");
PDF.SaveAs("pixel-perfect.pdf");

// Load external HTML assets like images, CSS, and JavaScript
// Set the optional BasePath as the file location to load assets from
using var AdvancedPDF = Renderer.RenderHtmlAsPdf("<img src='logo.png'><h1>Sample Text</h1>", @"C:\site\assets\");
AdvancedPDF.SaveAs("html-with-assets.pdf");
var Renderer = new IronPdf.ChromePdfRenderer();
// Render a PDF from a simple HTML string
using var PDF = Renderer.RenderHtmlAsPdf("<h1>Html with CSS and Images</h1>");
PDF.SaveAs("pixel-perfect.pdf");

// Load external HTML assets like images, CSS, and JavaScript
// Set the optional BasePath as the file location to load assets from
using var AdvancedPDF = Renderer.RenderHtmlAsPdf("<img src='logo.png'><h1>Sample Text</h1>", @"C:\site\assets\");
AdvancedPDF.SaveAs("html-with-assets.pdf");
$vbLabelText   $csharpLabel

輸出結果如下:

A Comparison of IronPDF with Apitron PDF SDK .NET - Figure 4: IronPDF 根據 URL 和 HTML/CSS 字串產生 PDF

IronPDF 根據 URL 和 HTML/CSS 字串產生 PDF

3.2. 使用 Apitron PDF 套件

Apitron PDF 不提供將 URL 或 HTML 轉換為 PDF 的方法。 它可以將PDF轉換為HTML。 但是,它還可以將 XML 檔案轉換為 PDF。 使用的 XML 檔案為:

<?xml version="1.0" encoding="utf-8"?>
<FlowDocument xmlns="Apitron.PDF.Kit.FlowLayout.v1">
  <Resources>
    <Image resourceId="logo" fileName="../../images/logo.png" />
  </Resources>
  <Styles>
    <Style selector="flowdocument">
      <Color value="Black" />
    </Style>
    <Style selector="grid">
      <InnerBorder thickness="1" />
      <InnerBorderColor value="Black" />
    </Style>
  </Styles>
  <Elements>
    <Image>
      <Properties>
        <Class value="logo" />
        <ResourceId value="logo" />
      </Properties>
    </Image>
    <TextBlock>
      <Properties>
        <Class value="header" />
        <Text value="Sample Interview Questions for Candidates" />
      </Properties>
    </TextBlock>
    <Br />
    <TextBlock>
      <Properties>
        <Class value="headerNote" />
        <Text value="To help facilitate the interview process, the Human Resources Department has compiled a list of questions that might be used during the phone and/or on-campus interviews. Some of the questions deal with the same content, but are phrased differently while other questions may not pertain to a specific discipline; however all of the questions are unbiased and appropriate to ask. We hope you'll find this helpful." />
      </Properties>
    </TextBlock>
  </Elements>
  <Properties>
    <Margin value="30,20,30,20" />
  </Properties>
</FlowDocument>
<?xml version="1.0" encoding="utf-8"?>
<FlowDocument xmlns="Apitron.PDF.Kit.FlowLayout.v1">
  <Resources>
    <Image resourceId="logo" fileName="../../images/logo.png" />
  </Resources>
  <Styles>
    <Style selector="flowdocument">
      <Color value="Black" />
    </Style>
    <Style selector="grid">
      <InnerBorder thickness="1" />
      <InnerBorderColor value="Black" />
    </Style>
  </Styles>
  <Elements>
    <Image>
      <Properties>
        <Class value="logo" />
        <ResourceId value="logo" />
      </Properties>
    </Image>
    <TextBlock>
      <Properties>
        <Class value="header" />
        <Text value="Sample Interview Questions for Candidates" />
      </Properties>
    </TextBlock>
    <Br />
    <TextBlock>
      <Properties>
        <Class value="headerNote" />
        <Text value="To help facilitate the interview process, the Human Resources Department has compiled a list of questions that might be used during the phone and/or on-campus interviews. Some of the questions deal with the same content, but are phrased differently while other questions may not pertain to a specific discipline; however all of the questions are unbiased and appropriate to ask. We hope you'll find this helpful." />
      </Properties>
    </TextBlock>
  </Elements>
  <Properties>
    <Margin value="30,20,30,20" />
  </Properties>
</FlowDocument>
XML

將此 XML 範本轉換為 PDF 的程式碼如下:

// Use Apitron's FlowDocument to convert XML to PDF
using (Stream stream = File.OpenRead("C:\PLACE YOUR EXACT PATH HERE\template.xml"), 
               outputStream = File.Create("fromTemplate.pdf"))
{
    ResourceManager resourceManager = new ResourceManager();
    FlowDocument doc = FlowDocument.LoadFromXml(stream, resourceManager);

    doc.Write(outputStream, resourceManager);
}
// Use Apitron's FlowDocument to convert XML to PDF
using (Stream stream = File.OpenRead("C:\PLACE YOUR EXACT PATH HERE\template.xml"), 
               outputStream = File.Create("fromTemplate.pdf"))
{
    ResourceManager resourceManager = new ResourceManager();
    FlowDocument doc = FlowDocument.LoadFromXml(stream, resourceManager);

    doc.Write(outputStream, resourceManager);
}
$vbLabelText   $csharpLabel

輸出結果如下:

A Comparison of IronPDF with Apitron PDF SDK .NET - Figure 5: Apitron PDF 文件

Apitron PDF 文件

比較 IronPDF 和 Apitron 的輸出結果,我們可以清楚地看到,IronPDF 使用 HTML 渲染生成了精美的文檔,甚至無需縮放圖像尺寸。而 Apitron 的輸出結果與 IronPDF 類似,但前提是 XML 檔案已註冊樣式。

4. 在PDF文件中新增頁首和頁尾

4.1. 使用 IronPDF

使用 IronPDF 新增頁首和頁尾非常簡單。 IronPDF 讓您可以新增頁碼和分頁符號、附加封面、頁邊距等。

以下是新增頁首和頁尾的程式碼:

var Renderer = new ChromePdfRenderer();

// Add a header
Renderer.RenderingOptions.FirstPageNumber = 1; // Use 2 if a cover page will be appended
Renderer.RenderingOptions.TextHeader.DrawDividerLine = true;
Renderer.RenderingOptions.TextHeader.CenterText = "This is the header text";
Renderer.RenderingOptions.TextHeader.Font = IronPdf.Font.FontTypes.Helvetica;
Renderer.RenderingOptions.TextHeader.FontSize = 12;
Renderer.RenderingOptions.MarginTop = 25; // Create 25mm space for header

// Add a footer too
Renderer.RenderingOptions.TextFooter.DrawDividerLine = true;
Renderer.RenderingOptions.TextFooter.Font = IronPdf.Font.FontTypes.Arial;
Renderer.RenderingOptions.TextFooter.FontSize = 12;
Renderer.RenderingOptions.TextFooter.LeftText = "{date} {time}";
Renderer.RenderingOptions.TextFooter.RightText = "{page} of {total-pages}";
Renderer.RenderingOptions.MarginTop = 25; // Create 25mm space for footer

using var AdvancedPDF = Renderer.RenderHtmlAsPdf("<img src='logo.png'><h1>This is header and footer generated pdf file</h1>", @"C:\site\assets\");
AdvancedPDF.SaveAs("html-with-assets.pdf");
var Renderer = new ChromePdfRenderer();

// Add a header
Renderer.RenderingOptions.FirstPageNumber = 1; // Use 2 if a cover page will be appended
Renderer.RenderingOptions.TextHeader.DrawDividerLine = true;
Renderer.RenderingOptions.TextHeader.CenterText = "This is the header text";
Renderer.RenderingOptions.TextHeader.Font = IronPdf.Font.FontTypes.Helvetica;
Renderer.RenderingOptions.TextHeader.FontSize = 12;
Renderer.RenderingOptions.MarginTop = 25; // Create 25mm space for header

// Add a footer too
Renderer.RenderingOptions.TextFooter.DrawDividerLine = true;
Renderer.RenderingOptions.TextFooter.Font = IronPdf.Font.FontTypes.Arial;
Renderer.RenderingOptions.TextFooter.FontSize = 12;
Renderer.RenderingOptions.TextFooter.LeftText = "{date} {time}";
Renderer.RenderingOptions.TextFooter.RightText = "{page} of {total-pages}";
Renderer.RenderingOptions.MarginTop = 25; // Create 25mm space for footer

using var AdvancedPDF = Renderer.RenderHtmlAsPdf("<img src='logo.png'><h1>This is header and footer generated pdf file</h1>", @"C:\site\assets\");
AdvancedPDF.SaveAs("html-with-assets.pdf");
$vbLabelText   $csharpLabel

輸出結果如下:

A Comparison of IronPDF with Apitron PDF SDK .NET - Figure 6: IronPDF 的頁首和頁尾

IronPDF 的頁首和頁尾

4.2. 使用 Apitron PDF 套件

Apitron PDF Kit 透過將 XML 結構格式的內容轉換為 PDF 來建立 PDF 檔案。 在 Apitron PDF Kit 中,可以使用PageHeaderPageFooter屬性來新增頁首和頁尾。 實現此功能的程式碼如下:

// Register document resources first
ResourceManager resourceManager = new ResourceManager();
resourceManager.RegisterResource(new Apitron.PDF.Kit.FixedLayout.Resources.XObjects.Image("logo", "../../data/logo.png"));

// Create the document
FlowDocument doc = new FlowDocument() { Margin = new Thickness(10) };

// Register styles
doc.StyleManager.RegisterStyle(".pageHeader", new Style() { Font = new Font(StandardFonts.TimesBold, 20) });
doc.StyleManager.RegisterStyle(".pageFooter", new Style() { Align = Align.Right });
doc.StyleManager.RegisterStyle("hr", new Style() { Height = 2, Margin = new Thickness(0, 5, 0, 5) });
doc.StyleManager.RegisterStyle(".content", new Style() { Align = Align.Left, Display = Display.InlineBlock });

// Fill the header section
doc.PageHeader.Class = "pageHeader";
doc.PageHeader.Add(new Image("logo") { Width = 100, Height = 50 });
doc.PageHeader.Add(new TextBlock("This document is intended for internal use only") { TextIndent = 20 });
doc.PageHeader.Add(new Hr());

// Fill the footer section
doc.PageFooter.Class = "pageFooter";
doc.PageFooter.Add(new Hr());
doc.PageFooter.Add(new TextBlock((ctx) => string.Format("Page {0} from&nbsp;", ctx.CurrentPage + 1)));
doc.PageFooter.Add(new PageCount(3) { Display = Display.Inline });

// Add pages
for (int i = 0; i < 2; ++i)
{
    doc.Add(new TextBlock("This is header and footer generation pdf file.") { Class = "content" });
    doc.Add(new PageBreak());
}

// Generate PDF
using (Stream stream = File.Create("out.pdf"))
{
    doc.Write(stream, resourceManager);
}

Process.Start("out.pdf");
// Register document resources first
ResourceManager resourceManager = new ResourceManager();
resourceManager.RegisterResource(new Apitron.PDF.Kit.FixedLayout.Resources.XObjects.Image("logo", "../../data/logo.png"));

// Create the document
FlowDocument doc = new FlowDocument() { Margin = new Thickness(10) };

// Register styles
doc.StyleManager.RegisterStyle(".pageHeader", new Style() { Font = new Font(StandardFonts.TimesBold, 20) });
doc.StyleManager.RegisterStyle(".pageFooter", new Style() { Align = Align.Right });
doc.StyleManager.RegisterStyle("hr", new Style() { Height = 2, Margin = new Thickness(0, 5, 0, 5) });
doc.StyleManager.RegisterStyle(".content", new Style() { Align = Align.Left, Display = Display.InlineBlock });

// Fill the header section
doc.PageHeader.Class = "pageHeader";
doc.PageHeader.Add(new Image("logo") { Width = 100, Height = 50 });
doc.PageHeader.Add(new TextBlock("This document is intended for internal use only") { TextIndent = 20 });
doc.PageHeader.Add(new Hr());

// Fill the footer section
doc.PageFooter.Class = "pageFooter";
doc.PageFooter.Add(new Hr());
doc.PageFooter.Add(new TextBlock((ctx) => string.Format("Page {0} from&nbsp;", ctx.CurrentPage + 1)));
doc.PageFooter.Add(new PageCount(3) { Display = Display.Inline });

// Add pages
for (int i = 0; i < 2; ++i)
{
    doc.Add(new TextBlock("This is header and footer generation pdf file.") { Class = "content" });
    doc.Add(new PageBreak());
}

// Generate PDF
using (Stream stream = File.Create("out.pdf"))
{
    doc.Write(stream, resourceManager);
}

Process.Start("out.pdf");
$vbLabelText   $csharpLabel

輸出結果如下:

A Comparison of IronPDF with Apitron PDF SDK .NET - Figure 7: Apitron 頭部和尾部

Apitron 頭部和尾部

5. 對 PDF 檔案進行數位簽名

5.1. 使用 IronPDF

PDF 處理最重要的功能之一是能夠對 PDF 文件進行數位簽章。 IronPDF 提供了完成此操作所需的所有工具。

using IronPdf;

// Cryptographically sign an existing PDF in 1 line of code!
new IronPdf.Signing.PdfSignature("Iron.p12", "123456").SignPdfFile("any.pdf");

/***** Advanced example for more control *****/

// 1. Create a PDF
var Renderer = new IronPdf.ChromePdfRenderer();
var doc = Renderer.RenderHtmlAsPdf("<h1>Testing 2048 bit digital security</h1>");

// 2. Create a Signature.
// You may create a .pfx or .p12 PDF signing certificate using Adobe Acrobat Reader.

var signature = new IronPdf.Signing.PdfSignature("Iron.pfx", "123456");

// 3. Handwritten signature graphic
signature.LoadSignatureImageFromFile("handwriting.png");

// 4. Sign the PDF with the PdfSignature. Multiple signing certificates may be used
doc.SignPdfWithDigitalSignature(signature);

// 5. The PDF is not signed until saved to file, stream or byte array.
doc.SaveAs("signed.pdf");
using IronPdf;

// Cryptographically sign an existing PDF in 1 line of code!
new IronPdf.Signing.PdfSignature("Iron.p12", "123456").SignPdfFile("any.pdf");

/***** Advanced example for more control *****/

// 1. Create a PDF
var Renderer = new IronPdf.ChromePdfRenderer();
var doc = Renderer.RenderHtmlAsPdf("<h1>Testing 2048 bit digital security</h1>");

// 2. Create a Signature.
// You may create a .pfx or .p12 PDF signing certificate using Adobe Acrobat Reader.

var signature = new IronPdf.Signing.PdfSignature("Iron.pfx", "123456");

// 3. Handwritten signature graphic
signature.LoadSignatureImageFromFile("handwriting.png");

// 4. Sign the PDF with the PdfSignature. Multiple signing certificates may be used
doc.SignPdfWithDigitalSignature(signature);

// 5. The PDF is not signed until saved to file, stream or byte array.
doc.SaveAs("signed.pdf");
$vbLabelText   $csharpLabel

5.2 使用 Apitron PDF 套件

使用 Apitron PDF Kit 在 PDF 檔案上新增簽名既耗時又需要一定的技術。

static void Main(string[] args)
{
    string fileName = "signedTwice.pdf";

    using (Stream stream = File.Create(fileName))
    {
        FlowDocument doc = new FlowDocument() { Margin = new Thickness(10) };
        doc.Add(new TextBlock("Signed using Apitron PDF Kit for .NET"));
        doc.Write(stream, new ResourceManager());
    }

    // Save
    Sign(fileName, "../../data/certs/JohnDoe.pfx", "password", "../../data/images/signatureImage.png", new Boundary(10, 750, 110, 800));
}

// Implementation of Sign Method
private static void Sign(string pathToDocument, string pathToCertificate, string password, string pathToSignatureImage, Boundary signatureViewLocation)
{
    // Open existing document and sign once
    using (Stream inputStream = new FileStream(pathToDocument, FileMode.Open, FileAccess.ReadWrite))
    {
        using (FixedDocument doc = new FixedDocument(inputStream))
        {
            string imageResourceId = Guid.NewGuid().ToString("N");
            string signatureFieldId = Guid.NewGuid().ToString("N");

            // Register signature image resource
            doc.ResourceManager.RegisterResource(new Image(imageResourceId, pathToSignatureImage));

            // Create first signature field and initialize it using a stored certificate
            SignatureField signatureField = new SignatureField(signatureFieldId);
            using (Stream signatureDataStream = File.OpenRead(pathToCertificate))
            {
                signatureField.Signature = Signature.Create(new Pkcs12Store(signatureDataStream, password));
            }

            // Add signature fields to the document
doc.AcroForm.Fields.Add(signatureField);

            // Create first signature view using the image resource
            SignatureFieldView signatureView = new SignatureFieldView(signatureField, signatureViewLocation);
            signatureView.ViewSettings.Graphic = Graphic.Image;
            signatureView.ViewSettings.GraphicResourceID = imageResourceId;
            signatureView.ViewSettings.Description = Description.None;

            // Add views to page annotations collection
doc.Pages[0].Annotations.Add(signatureView);

            // Save as incremental update
doc.Save();
        }
    }
}
static void Main(string[] args)
{
    string fileName = "signedTwice.pdf";

    using (Stream stream = File.Create(fileName))
    {
        FlowDocument doc = new FlowDocument() { Margin = new Thickness(10) };
        doc.Add(new TextBlock("Signed using Apitron PDF Kit for .NET"));
        doc.Write(stream, new ResourceManager());
    }

    // Save
    Sign(fileName, "../../data/certs/JohnDoe.pfx", "password", "../../data/images/signatureImage.png", new Boundary(10, 750, 110, 800));
}

// Implementation of Sign Method
private static void Sign(string pathToDocument, string pathToCertificate, string password, string pathToSignatureImage, Boundary signatureViewLocation)
{
    // Open existing document and sign once
    using (Stream inputStream = new FileStream(pathToDocument, FileMode.Open, FileAccess.ReadWrite))
    {
        using (FixedDocument doc = new FixedDocument(inputStream))
        {
            string imageResourceId = Guid.NewGuid().ToString("N");
            string signatureFieldId = Guid.NewGuid().ToString("N");

            // Register signature image resource
            doc.ResourceManager.RegisterResource(new Image(imageResourceId, pathToSignatureImage));

            // Create first signature field and initialize it using a stored certificate
            SignatureField signatureField = new SignatureField(signatureFieldId);
            using (Stream signatureDataStream = File.OpenRead(pathToCertificate))
            {
                signatureField.Signature = Signature.Create(new Pkcs12Store(signatureDataStream, password));
            }

            // Add signature fields to the document
doc.AcroForm.Fields.Add(signatureField);

            // Create first signature view using the image resource
            SignatureFieldView signatureView = new SignatureFieldView(signatureField, signatureViewLocation);
            signatureView.ViewSettings.Graphic = Graphic.Image;
            signatureView.ViewSettings.GraphicResourceID = imageResourceId;
            signatureView.ViewSettings.Description = Description.None;

            // Add views to page annotations collection
doc.Pages[0].Annotations.Add(signatureView);

            // Save as incremental update
doc.Save();
        }
    }
}
$vbLabelText   $csharpLabel

各個庫的輸出結果基本上相同。 很明顯,IronPDF 在處理 PDF 內容方面更加簡單方便。 輸出的PDF文件會列印出證書和簽名。

使用 Bootstrap 5 和 IronPDF 建立作品集圖庫

IronPDF 的 Chrome V8 渲染引擎完全支援現代 Bootstrap 5 元件,讓您能夠產生具有專業作品集圖庫的視覺效果驚人的 PDF 文件。 此範例示範了網格佈局、懸停效果、漸層疊加和類別徽章——這些功能使用 Apitron PDF SDK 等傳統 PDF 庫很難實現。

using IronPdf;

var renderer = new ChromePdfRenderer();

string portfolioGallery = @"
<!DOCTYPE html>
<html>
<head>
    <meta charset='utf-8'>
    <link href='https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css' rel='stylesheet'>
    <style>
        .gallery-item {
            position: relative;
            overflow: hidden;
            border-radius: 10px;
            box-shadow: 0 4px 6px rgba(0,0,0,0.1);
        }
        .gallery-item img {
            width: 100%;
            height: 250px;
            object-fit: cover;
            transition: transform 0.3s;
        }
        .gallery-item:hover img {
            transform: scale(1.1);
        }
        .gallery-overlay {
            position: absolute;
            bottom: 0;
            left: 0;
            right: 0;
            background: linear-gradient(to top, rgba(0,0,0,0.8), transparent);
            padding: 20px;
            color: white;
        }
        .category-badge {
            position: absolute;
            top: 10px;
            right: 10px;
        }
        @media print {
            .gallery-item { page-break-inside: avoid; }
        }
    </style>
</head>
<body>
    <div class='container py-5'>
        <div class='text-center mb-5'>
            <h1 class='display-4'>Design Portfolio</h1>
            <p class='lead text-muted'>Showcase of PDF Document Designs</p>
        </div>

        <div class='row mb-4'>
            <div class='col-12'>
                <div class='btn-group' role='group'>
                    <button class='btn btn-primary'>All Projects</button>
                    <button class='btn btn-outline-primary'>Invoices</button>
                    <button class='btn btn-outline-primary'>Reports</button>
                    <button class='btn btn-outline-primary'>Forms</button>
                    <button class='btn btn-outline-primary'>Certificates</button>
                </div>
            </div>
        </div>

        <div class='row g-4'>
            <div class='col-md-4'>
                <div class='gallery-item'>
                    <span class='badge bg-primary category-badge'>Invoice</span>
                    <svg width='100%' height='250' style='background: linear-gradient(135deg, #667eea 0%, #764ba2 100%)'>
                        <text x='50%' y='50%' text-anchor='middle' fill='white' font-size='48' opacity='0.3'>📄</text>
                    </svg>
                    <div class='gallery-overlay'>
                        <h5 class='mb-1'>Professional Invoice Template</h5>
                        <small>Corporate billing with itemized details</small>
                    </div>
                </div>
            </div>

            <div class='col-md-4'>
                <div class='gallery-item'>
                    <span class='badge bg-success category-badge'>Report</span>
                    <svg width='100%' height='250' style='background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%)'>
                        <text x='50%' y='50%' text-anchor='middle' fill='white' font-size='48' opacity='0.3'>📊</text>
                    </svg>
                    <div class='gallery-overlay'>
                        <h5 class='mb-1'>Analytics Dashboard Report</h5>
                        <small>Data visualization and metrics</small>
                    </div>
                </div>
            </div>

            <div class='col-md-4'>
                <div class='gallery-item'>
                    <span class='badge bg-warning category-badge'>Certificate</span>
                    <svg width='100%' height='250' style='background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%)'>
                        <text x='50%' y='50%' text-anchor='middle' fill='white' font-size='48' opacity='0.3'>🏆</text>
                    </svg>
                    <div class='gallery-overlay'>
                        <h5 class='mb-1'>Award Certificate</h5>
                        <small>Professional achievement recognition</small>
                    </div>
                </div>
            </div>

            <div class='col-md-4'>
                <div class='gallery-item'>
                    <span class='badge bg-info category-badge'>Form</span>
                    <svg width='100%' height='250' style='background: linear-gradient(135deg, #fa709a 0%, #fee140 100%)'>
                        <text x='50%' y='50%' text-anchor='middle' fill='white' font-size='48' opacity='0.3'>📝</text>
                    </svg>
                    <div class='gallery-overlay'>
                        <h5 class='mb-1'>Application Form</h5>
                        <small>Multi-page data collection</small>
                    </div>
                </div>
            </div>

            <div class='col-md-4'>
                <div class='gallery-item'>
                    <span class='badge bg-danger category-badge'>Invoice</span>
                    <svg width='100%' height='250' style='background: linear-gradient(135deg, #30cfd0 0%, #330867 100%)'>
                        <text x='50%' y='50%' text-anchor='middle' fill='white' font-size='48' opacity='0.3'>💰</text>
                    </svg>
                    <div class='gallery-overlay'>
                        <h5 class='mb-1'>Payment Receipt</h5>
                        <small>Transaction confirmation document</small>
                    </div>
                </div>
            </div>

            <div class='col-md-4'>
                <div class='gallery-item'>
                    <span class='badge bg-secondary category-badge'>Report</span>
                    <svg width='100%' height='250' style='background: linear-gradient(135deg, #a8edea 0%, #fed6e3 100%)'>
                        <text x='50%' y='50%' text-anchor='middle' fill='white' font-size='48' opacity='0.3'>📈</text>
                    </svg>
                    <div class='gallery-overlay'>
                        <h5 class='mb-1'>Financial Statement</h5>
                        <small>Quarterly performance overview</small>
                    </div>
                </div>
            </div>
        </div>

        <div class='text-center mt-5'>
            <p class='text-muted'>All templates rendered with IronPDF's Chromium engine</p>
            <div class='d-flex justify-content-center gap-2'>
                <span class='badge bg-primary'>Bootstrap 5</span>
                <span class='badge bg-success'>Responsive</span>
                <span class='badge bg-info'>Print-Ready</span>
            </div>
        </div>
    </div>
</body>
</html>";

var pdf = renderer.RenderHtmlAsPdf(portfolioGallery);
pdf.SaveAs("portfolio-gallery.pdf");
using IronPdf;

var renderer = new ChromePdfRenderer();

string portfolioGallery = @"
<!DOCTYPE html>
<html>
<head>
    <meta charset='utf-8'>
    <link href='https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css' rel='stylesheet'>
    <style>
        .gallery-item {
            position: relative;
            overflow: hidden;
            border-radius: 10px;
            box-shadow: 0 4px 6px rgba(0,0,0,0.1);
        }
        .gallery-item img {
            width: 100%;
            height: 250px;
            object-fit: cover;
            transition: transform 0.3s;
        }
        .gallery-item:hover img {
            transform: scale(1.1);
        }
        .gallery-overlay {
            position: absolute;
            bottom: 0;
            left: 0;
            right: 0;
            background: linear-gradient(to top, rgba(0,0,0,0.8), transparent);
            padding: 20px;
            color: white;
        }
        .category-badge {
            position: absolute;
            top: 10px;
            right: 10px;
        }
        @media print {
            .gallery-item { page-break-inside: avoid; }
        }
    </style>
</head>
<body>
    <div class='container py-5'>
        <div class='text-center mb-5'>
            <h1 class='display-4'>Design Portfolio</h1>
            <p class='lead text-muted'>Showcase of PDF Document Designs</p>
        </div>

        <div class='row mb-4'>
            <div class='col-12'>
                <div class='btn-group' role='group'>
                    <button class='btn btn-primary'>All Projects</button>
                    <button class='btn btn-outline-primary'>Invoices</button>
                    <button class='btn btn-outline-primary'>Reports</button>
                    <button class='btn btn-outline-primary'>Forms</button>
                    <button class='btn btn-outline-primary'>Certificates</button>
                </div>
            </div>
        </div>

        <div class='row g-4'>
            <div class='col-md-4'>
                <div class='gallery-item'>
                    <span class='badge bg-primary category-badge'>Invoice</span>
                    <svg width='100%' height='250' style='background: linear-gradient(135deg, #667eea 0%, #764ba2 100%)'>
                        <text x='50%' y='50%' text-anchor='middle' fill='white' font-size='48' opacity='0.3'>📄</text>
                    </svg>
                    <div class='gallery-overlay'>
                        <h5 class='mb-1'>Professional Invoice Template</h5>
                        <small>Corporate billing with itemized details</small>
                    </div>
                </div>
            </div>

            <div class='col-md-4'>
                <div class='gallery-item'>
                    <span class='badge bg-success category-badge'>Report</span>
                    <svg width='100%' height='250' style='background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%)'>
                        <text x='50%' y='50%' text-anchor='middle' fill='white' font-size='48' opacity='0.3'>📊</text>
                    </svg>
                    <div class='gallery-overlay'>
                        <h5 class='mb-1'>Analytics Dashboard Report</h5>
                        <small>Data visualization and metrics</small>
                    </div>
                </div>
            </div>

            <div class='col-md-4'>
                <div class='gallery-item'>
                    <span class='badge bg-warning category-badge'>Certificate</span>
                    <svg width='100%' height='250' style='background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%)'>
                        <text x='50%' y='50%' text-anchor='middle' fill='white' font-size='48' opacity='0.3'>🏆</text>
                    </svg>
                    <div class='gallery-overlay'>
                        <h5 class='mb-1'>Award Certificate</h5>
                        <small>Professional achievement recognition</small>
                    </div>
                </div>
            </div>

            <div class='col-md-4'>
                <div class='gallery-item'>
                    <span class='badge bg-info category-badge'>Form</span>
                    <svg width='100%' height='250' style='background: linear-gradient(135deg, #fa709a 0%, #fee140 100%)'>
                        <text x='50%' y='50%' text-anchor='middle' fill='white' font-size='48' opacity='0.3'>📝</text>
                    </svg>
                    <div class='gallery-overlay'>
                        <h5 class='mb-1'>Application Form</h5>
                        <small>Multi-page data collection</small>
                    </div>
                </div>
            </div>

            <div class='col-md-4'>
                <div class='gallery-item'>
                    <span class='badge bg-danger category-badge'>Invoice</span>
                    <svg width='100%' height='250' style='background: linear-gradient(135deg, #30cfd0 0%, #330867 100%)'>
                        <text x='50%' y='50%' text-anchor='middle' fill='white' font-size='48' opacity='0.3'>💰</text>
                    </svg>
                    <div class='gallery-overlay'>
                        <h5 class='mb-1'>Payment Receipt</h5>
                        <small>Transaction confirmation document</small>
                    </div>
                </div>
            </div>

            <div class='col-md-4'>
                <div class='gallery-item'>
                    <span class='badge bg-secondary category-badge'>Report</span>
                    <svg width='100%' height='250' style='background: linear-gradient(135deg, #a8edea 0%, #fed6e3 100%)'>
                        <text x='50%' y='50%' text-anchor='middle' fill='white' font-size='48' opacity='0.3'>📈</text>
                    </svg>
                    <div class='gallery-overlay'>
                        <h5 class='mb-1'>Financial Statement</h5>
                        <small>Quarterly performance overview</small>
                    </div>
                </div>
            </div>
        </div>

        <div class='text-center mt-5'>
            <p class='text-muted'>All templates rendered with IronPDF's Chromium engine</p>
            <div class='d-flex justify-content-center gap-2'>
                <span class='badge bg-primary'>Bootstrap 5</span>
                <span class='badge bg-success'>Responsive</span>
                <span class='badge bg-info'>Print-Ready</span>
            </div>
        </div>
    </div>
</body>
</html>";

var pdf = renderer.RenderHtmlAsPdf(portfolioGallery);
pdf.SaveAs("portfolio-gallery.pdf");
$vbLabelText   $csharpLabel

這段程式碼產生一個專業的 PDF 作品集,具有響應式網格佈局、視覺類別徽章、漸層疊加層和懸停效果。 Chrome 渲染引擎保留了所有 Bootstrap 樣式、CSS Grid 佈局和自訂 CSS 屬性——這是傳統 PDF 庫難以複製的功能。

與 Apitron PDF SDK 相比的主要優勢:

  • 原生支援 Bootstrap 5,無需轉換 CSS Grid 和 Flexbox 佈局完美渲染
  • 漸層背景與現代 CSS 效果
  • 程式碼更簡潔,輸出品質更高

有關 Bootstrap PDF 產生的完整指南,請參閱HTML 前往 PDF Bootstrap 指南

6. 定價和許可

IronPDF定價和許可

IronPDF 是一個 C# 庫,可免費用於開發,並可隨時授權用於商業用途。我們提供個人開發者、代理商、跨國組織以及 SaaS 和 OEM 分發的專案授權。 所有許可證均提供 30 天退款保證、一年支援和升級、開發/測試/生產有效期以及永久許可證(一次性購買)。

Lite 套餐售價為$799 ,無任何後續費用。 更多詳細資訊和選擇最佳許可證的協助可在IronPDF 產品許可頁面上找到。

A Comparison of IronPDF with Apitron PDF SDK .NET - Figure 8: IronPDF 許可

IronPDF 許可

Apitron PDF 套件定價和許可

目前有兩種授權方案正在使用中—現代許可和傳統許可。 如果您已經擁有許可證,那麼舊版許可證方案將繼續有效,直到您的許可證到期為止。 之後,您需要聯絡客戶支援部門進行過渡。 如果您是新客戶,則現代授權方案對您適用。

根據現行製度,許可證分為三個等級:

-評估- 三個月的評估期,使用功能齊全的產品。 只需從 NuGet 下載軟體包即可開始開發。 -社區- 在您的非商業項目中免費使用功能齊全的產品。 需要獲得批准。 -商業用途- 以上未描述的任何用途。 價格取決於使用模式。

結論

IronPDF 庫可以從 HTML、JS、CSS、JPG、PNG、GIF 和 SVG 等文件類型建立像素級完美的 PDF。 Chromium 引擎有助於渲染 HTML 檔案或 URL,從而產生完美的 PDF 輸出。

Apitron 可讓您使用固定佈局 API 建立 PDF,該 API 的實作方式與 PDF 規範 100% 相容。 作為一種類似於 HTML 和 CSS 的樣式驅動型內容產生方法,這種固定佈局 API 使您能夠在幾分鐘內創建精美的報告、帳單、目錄等等。 它還支援建立 XML 模板。

Apitron PDF 的授權價格未在其網站上公佈。您需要聯絡客服,根據您的使用情況取得報價。 另一方面,IronPDF在其網站上清楚地展示了許可協議。這使得IronPDF在競爭對手中脫穎而出,並允許用戶根據自身需求做出明智的選擇。

使用 IronPDF,您可以比使用 Apitron PDF 更輕鬆地處理 PDF 檔案。 IronPDF 使用戶能夠以更少的程式碼行來完成複雜的 PDF 作業。 IronPDF 提供多種方法從多種文件類型產生 PDF,而 Apitron 只能將 XML 文件轉換為 PDF 文件。 與 Apitron 相比,IronPDF 無需添加任何技術選項即可實現完美的輸出。

Iron Software 的所有客戶都可以選擇以購買兩款產品的價格購買該公司全部五款產品。 您可以免費試用 IronPDF 30 天,體驗其完整功能。 請造訪IronSoftware.com購買 Iron Software 全套產品。

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

常見問題解答

如何在C#中將HTML轉換為PDF?

您可以使用 IronPDF 的RenderHtmlAsPdf方法將 HTML 字串轉換為 PDF。您也可以使用RenderHtmlFileAsPdf將 HTML 檔案轉換為 PDF。

IronPDF 提供哪些 PDF 建立功能?

IronPDF 支援從 HTML、CSS 和 JavaScript 建立 PDF,載入 URL,提取文字和圖形,合併 PDF 等功能。它相容於 .NET Core、Azure、AWS、Docker、Linux 和 Windows。

如何在C#中對PDF進行數位簽章?

使用 IronPDF,您可以使用 PDF 簽名憑證對 PDF 進行數位簽名,只需幾行程式碼即可整合該憑證。

IronPDF有哪些安裝選項?

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

IronPDF有免費版本嗎?

是的,IronPDF 提供免費的開發版本以及商業許可。詳細的定價信息,包括 30 天退款保證,可在其網站上找到。

Apitron PDF Kit 如何處理 HTML 到 PDF 的轉換?

Apitron PDF Kit 不支援直接將 HTML 文件轉換為 PDF 文件,但可以將 XML 文件轉換為 PDF 文件。

Apitron PDF Kit 的主要特點是什麼?

Apitron PDF Kit 提供全面的 PDF 編輯功能,包括新增圖像、繪圖、文字、簽署文件以及合併或分割 PDF 文件。但是,它不具備直接將 HTML 轉換為 PDF 的功能。

如何在 C# 中為 PDF 新增頁首和頁尾?

IronPDF 讓您可以使用AddTextHeaderAddTextFooter等方法輕鬆地為 PDF 添加頁首和頁尾。

Apitron PDF Kit有哪些授權許可選項?

Apitron PDF Kit 提供三個月的免費試用期,並為非商業項目提供社區許可。如需商業用途,請直接聯絡他們以取得報價。

對於 .NET 開發而言,哪個 PDF 函式庫比較容易使用?

與 Apitron PDF Kit 相比,IronPDF 通常更容易用於 .NET 開發,它提供了更直接的 API,並且對於複雜的任務所需的程式碼行數更少。

柯蒂斯·週
技術撰稿人

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

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