產品比較

IronPDF與Apitron PDF Kit之間的比較

發佈 2022年12月11日
分享:

在C#中,處理PDF檔案對開發者來說是一個挑戰。創建這些檔案的內容時需要考慮很多因素,將內容從不同格式轉換為PDF時更是如此。自動化現在是軟體開發過程的關鍵。這些問題已經通過設計可幫助讀取、寫入、創建和修改PDF文件的程式庫來解決,這些程式庫還可以編輯其屬性並將其從其他格式轉換為PDF。

在這篇博客文章中,將比較兩個適用於.NET和.NET Core的PDF程式庫。這兩個程式庫是:

  • IronPDF程式庫
  • Apitron PDF Kit

IronPDF和Apitron PDF Kit是兩個為.NET和.NET Core提供PDF操作功能的程式庫。它們都可用於文檔字段轉換和操作任務。它們都還可以創建書籤。下一個問題是決定哪個C# PDF .NET程式庫最適合我們的.NET項目。本比較文章將幫助您在這兩個PDF程式庫之間進行選擇。

首先,讓我們看看這兩個程式庫提供了什麼功能,然後進行比較本身。

Apitron PDF Kit 函式庫及其功能

Apitron PDF Kit 是一個 .NET 元件,允許您任意操作或轉換 PDF 文件。您可以添加圖片、圖形和文本,簽署文件等等。您還可以編輯現有內容。Apitron PDF Kit .NET 元件可用於創建跨多平台的行動、桌面、網路、Windows 及雲端應用程式。

使用這個 PDF SDK,您將能夠:

  • 提取、修改和添加圖形 (文字、圖片、繪圖)
  • 分割或合併PDF文件
  • 填寫或創建帶有密碼保護的PDF表單,FDF支持
  • 創建帶有可選內容組的多層PDF文件 ( OCG )
  • 從文件中添加或移除欄位
  • 使用從右至左或雙向文字創建頁面內容
  • 檢查文件內的資源 - 定義的字體、嵌入文件
  • 為PDF文件進行數位簽名並檢查現有簽名

IronPDF 的主要功能

開發者,尤其是 C# 程式設計師,會非常喜愛 IronPDF .NET 庫。使用這個令人驚豔的工具,你可以輕鬆建立 .NET Core PDF 處理應用程式。

IronPDF 使用 .NET Chromium 引擎來轉換 HTML 頁面 (在程式碼或網址形式中) 將HTML和圖片製作成PDF文件。完全不需要使用複雜的API來定位導航物件或設計來自HTML的PDF。IronPDF支援標準的網頁文件,包括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 網頁表單轉換為可打印的 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 Kit 安裝

  3. 創建 PDF 文檔

  4. 在 PDF 中創建標題和頁脚

  5. 為 PDF 數字簽名

  6. 定價和許可

  7. 總結

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
  • 按下 Enter
  • 這將下載並安裝套件
  • 重新載入你的專案並開始使用它

1.3. 直接下載 NuGet 套件

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

IronPDF 已下載並準備好使用。然而,在此之前,我們應該安裝 Apitron PDF 庫。

2. Apitron PDF Kit 安裝

對於 .NET Core 應用程式,我們可以使用 NuGet Package Manager 安裝 Apitron,或從下載並安裝 Apitron。 NuGet 網站直接。

  • 在 Visual Studio 中打開 NuGet 套件,就像我們在 IronPDF 中所做的一樣。
  • 搜尋 Apitron.PDF.Kit。
  • 在當前項目中點擊安裝。
A Comparison of IronPDF with Apitron PDF SDK .NET - Figure 3: Apitron PDF Kit 搜索

Apitron PDF Kit 搜索

您也可以使用 NuGet 套件管理器主控台安裝 Apitron。請按照 IronPDF 中提到的「使用開發人員命令提示字元」步驟,並輸入以下指令:

Install-Package Apitron.PDF.Kit

按 ENTER。它將下載並安裝 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;
Imports Apitron.PDF.Kit
Imports Apitron.PDF.Kit.FixedLayout.Resources
Imports Apitron.PDF.Kit.FixedLayout.Resources.Fonts
Imports Apitron.PDF.Kit.FlowLayout.Content
Imports Apitron.PDF.Kit.Styles
Imports Apitron.PDF.Kit.Styles.Appearance
Imports Font = Apitron.PDF.Kit.Styles.Text.Font
VB   C#

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

3. 創建 PDF 文件

3.1. 使用 IronPDF

IronPDF 有多種創建 PDF 的方法。讓我們來看看兩個重要的。

現有網址轉換為 PDF

IronPDF 使得轉換任何網址為 PDF 變得容易。以下程式碼幫助將網址轉換為 PDF。

IronPdf.ChromePdfRenderer Renderer = new IronPdf.ChromePdfRenderer();
using var Pdf = Renderer.RenderUrlAsPdf("https://ironpdf.com/");
Pdf.SaveAs("url.pdf");
IronPdf.ChromePdfRenderer Renderer = new IronPdf.ChromePdfRenderer();
using var Pdf = Renderer.RenderUrlAsPdf("https://ironpdf.com/");
Pdf.SaveAs("url.pdf");
Dim Renderer As New IronPdf.ChromePdfRenderer()
Dim Pdf = Renderer.RenderUrlAsPdf("https://ironpdf.com/")
Pdf.SaveAs("url.pdf")
VB   C#

HTML Input String to PDF

以下程式碼說明如何從 HTML 字串渲染 PDF 文件。您可以僅使用 HTML,或將其與 CSS、圖片和 JavaScript 結合使用。

var Renderer = new IronPdf.ChromePdfRenderer();
using var PDF = Renderer.RenderHtmlAsPdf("<h1>Html with CSS and Images</h1>");
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='logo.png'><h1>Sample Text</h1>", @"C:\site\assets\");
AdvancedPDF.SaveAs("html-with-assets.pdf");
var Renderer = new IronPdf.ChromePdfRenderer();
using var PDF = Renderer.RenderHtmlAsPdf("<h1>Html with CSS and Images</h1>");
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='logo.png'><h1>Sample Text</h1>", @"C:\site\assets\");
AdvancedPDF.SaveAs("html-with-assets.pdf");
Dim Renderer = New IronPdf.ChromePdfRenderer()
Dim PDF = Renderer.RenderHtmlAsPdf("<h1>Html with CSS and Images</h1>")
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
Dim AdvancedPDF = Renderer.RenderHtmlAsPdf("<img src='logo.png'><h1>Sample Text</h1>", "C:\site\assets\")
AdvancedPDF.SaveAs("html-with-assets.pdf")
VB   C#

輸出如下:

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

將此 XML 模板轉換為 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);
}
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);
}
Using stream As Stream = File.OpenRead("C:\PLACE YOUR EXACT PATH HERE\template.xml"), outputStream As Stream = File.Create("fromTemplate.pdf")
	Dim resourceManager As New ResourceManager()

	Dim doc As FlowDocument = FlowDocument.LoadFromXml(stream, resourceManager)

	doc.Write(outputStream, resourceManager)
End Using
VB   C#

輸出如下:

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");
Dim 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

Dim 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")
VB   C#

輸出如下:

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

IronPDF 頁首和頁尾

4.2. 使用 Apitron PDF Kit

Apitron PDF Kit 透過將 XML 結構格式的內容轉換為 PDF 來創建 PDF。在 Apitron PDF Kit 中,可以使用 PageHeaderPageFooter 屬性添加頁首和頁尾。添加頁首和頁尾的代碼如下:

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

// create 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 doc's resources first
ResourceManager resourceManager = new ResourceManager();
resourceManager.RegisterResource(new Apitron.PDF.Kit.FixedLayout.Resources.XObjects.Image("logo","../../data/logo.png"));

// create 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 doc's resources first
Dim resourceManager As New ResourceManager()
resourceManager.RegisterResource(New Apitron.PDF.Kit.FixedLayout.Resources.XObjects.Image("logo","../../data/logo.png"))

' create document
Dim doc As New FlowDocument() With {.Margin = New Thickness(10)}

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

' fill the header section
doc.PageHeader.Class = "pageHeader"
doc.PageHeader.Add(New Image("logo") With {
	.Width = 100,
	.Height = 50
})
doc.PageHeader.Add(New TextBlock("This document is intended for internal use only") With {.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(Function(ctx) String.Format("Page {0} from&nbsp;",ctx.CurrentPage+1)))
doc.PageFooter.Add(New PageCount(3) With {.Display = Display.Inline})

' add pages
For i As Integer = 0 To 1
	doc.Add(New TextBlock("This is header and footer generation pdf file.") With {.Class = "content"})
	doc.Add(New PageBreak())
Next i

' generate PDF
Using stream As Stream = File.Create("out.pdf")
	doc.Write(stream, resourceManager)
End Using

Process.Start("out.pdf")
VB   C#

輸出如下:

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");
Imports IronPdf

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

'''*** Advanced example for more control ****

' 1. Create a PDF
Dim Renderer = New IronPdf.ChromePdfRenderer()
Dim 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.

Dim 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")
VB   C#

5.2 使用 Apitron PDF Kit

使用 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();
        }
    }
}
Shared Sub Main(ByVal args() As String)
	Dim fileName As String = "signedTwice.pdf"

	Using stream As Stream = File.Create(fileName)
		Dim doc As New FlowDocument() With {.Margin = New Thickness(10)}
		doc.Add(New TextBlock("Signed using Apitron PDF Kit for .NET"))
		doc.Write(stream,New ResourceManager())
	End Using

	' save
	Sign(fileName, "../../data/certs/JohnDoe.pfx", "password", "../../data/images/signatureImage.png", New Boundary(10, 750, 110, 800))
End Sub

' Implementation of Sign Method
Private Shared Sub Sign(ByVal pathToDocument As String, ByVal pathToCertificate As String, ByVal password As String, ByVal pathToSignatureImage As String, ByVal signatureViewLocation As Boundary)
	' open existing document and sign once
	Using inputStream As Stream = New FileStream(pathToDocument, FileMode.Open, FileAccess.ReadWrite)
		Using doc As New FixedDocument(inputStream)
			Dim imageResourceId As String = Guid.NewGuid().ToString("N")
			Dim signatureFieldId As String = 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
			Dim signatureField As New SignatureField(signatureFieldId)
			Using signatureDataStream As Stream = File.OpenRead(pathToCertificate)
				signatureField.Signature = Signature.Create(New Pkcs12Store(signatureDataStream,password))
			End Using

			' add signature fields to the document
			doc.AcroForm.Fields.Add(signatureField)

			' create first signature view using the image resource
			Dim signatureView As 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()
		End Using
	End Using
End Sub
VB   C#

輸出對於所有函式庫來說幾乎是一樣的。你可以明顯看出,IronPDF在操作PDF內容方面更容易和方便。輸出的PDF已簽署證書且上面印有簽名。

6. 價格和授權

IronPDF 價格和授權

IronPDF 是一個 C# 庫,可免費用於開發,並且可以隨時購買商業使用許可。單個開發人員、代理機構和跨國組織的項目授權,以及 SaaS 和 OEM 重發放授權,都可以獲得。所有授權均提供 30 天退款保證、一年支持和升級、開發/測試/生產有效性以及永久授權。 (一次性購買)精簡套裝目前售價 $749,且無需額外支出。更多詳細資訊及選擇最佳授權方案的協助請參見 產品授權頁面.

A Comparison of IronPDF with Apitron PDF SDK .NET - Figure 8: IronPDF 授權

IronPDF 授權

Apitron PDF Kit 定價和授權

目前有兩種授權方案:現代和傳統。如果您已經擁有授權,那麼傳統授權方案將對您有效,直到您的授權過期。之後,您需要聯繫客戶支持以進行過渡。現代授權方案僅適用於新的客戶。

在現代方案下,有三個授權層級:

  • 評估 - 三個月的評估期,可以使用全功能產品。只需從 NuGet 下載包並開始開發。
  • 社區 - 在您的非商業項目中無需付費地使用全功能產品。需經過批准。
  • 商業 - 以上未描述的任何使用情況。定價取決於使用模式。

如需進一步購買詳情,您可以 聯繫Apitron銷售代表.

結論

IronPDF 庫能從 HTML、JS、CSS、JPG、PNG、GIF 和 SVG 等文件類型創建像素完美的 PDF。Chromium 引擎有助於渲染 HTML 文件或 URL,以提供完美的 PDF 輸出。

Apitron 使用固定佈局 API 創建 PDF,實施 100% 與 PDF 規範兼容。作為一種基於樣式的內容生成方法,類似於 HTML 和 CSS,這個固定佈局 API 允許您在幾分鐘內創建驚人的報告、賬單、目錄等。它還支持創建 XML 模板。

Apitron PDF 的授權價格在其網站上不可用。您需要聯繫支持部門並根據您的使用情況獲取報價。另一方面,IronPDF 在其網站上顯示了非常清晰的授權包。這使得 IronPDF 在其競爭對手中脫穎而出,並允許用戶根據自己的需求明智地選擇。

使用 IronPDF,與使用 Apitron PDF 相比,您可以更輕鬆地處理 PDF 文件。IronPDF 允許用戶為挑戰性的 PDF 工作編寫更少的代碼。IronPDF 提供多種方法從多種文件類型生成 PDF,而 Apitron 只能將 XML 文件轉換為 PDF 附件。在 IronPDF 中不需增加任何技術選項即可實現完美的輸出,相較於 Apitron。

所有 Iron Software 的客戶都可以以購買兩個產品的價格購買該公司所有五個產品。試試 免費30天試用 測試其全部功能。購買完整的 Iron Software 產品套件 這裡.

< 上一頁
Telerik HTML 轉 PDF 生成器 與 IronPDF
下一個 >
IronPDF 與 GroupDocs 的比較

準備開始了嗎? 版本: 2024.10 剛剛發布

免費 NuGet 下載 總下載次數: 10,993,239 查看許可證 >