产品比较

IronPDF和XFINIUM.PDF的比较

发布 2022年九月27日
分享:

不断改进的技术意味着为每个人,尤其是开发人员提供更智能的解决方案。现在,自动化已成为软件开发流程的关键。多年来,使用 C# PDF 文件一直是开发人员面临的难题。在为 PDF 文件创建内容时需要考虑很多因素,而将不同格式的内容转换为 PDF 时更是如此。现在,随着多个库的构建,这些问题已迎刃而解,这些库旨在帮助从不同格式读取、写入、创建和转换为 PDF。

本文将对 .NET 和 .NET Core 开发人员最常用的两个 PDF 库进行比较。这两个库是

  • IronPDF 库
  • XFININIUM.PDF 库

IronPDF 和 XFININUM.PDF 是两个库,它们提供了在 .NET 和 .NET Core 中创建、操作和打印 PDF 的方法。下一个问题是决定哪个 C# PDF 库最适合您的 .NET 项目。您可以通过阅读以下两个库之间的比较及其各自在 PDF 转换和操作方面的突出功能来权衡自己的决定。

首先,让我们看看这两个库都有哪些功能,然后再进行比较。

XFINIUM.PDF 库及其功能

XFINIUM.PDF 库是一个用于 PDF 开发的跨平台库。它为业余和高级 PDF 开发人员提供了多种功能。无论您是要创建报告、填写 PDF 表单、构建 PDF 作品集、编辑 PDF 报告中的敏感数据,还是将 PDF 报告转换为多页 TIFF 图像,XFINIUM.PDF 库都能满足您的需求。

XFINIUM.PDF 有两个版本:生成器版本(包括 PDF 制作和编辑)和查看器版本(包含生成器版本的所有功能以及 PDF 渲染和 PDF 查看功能)。功能部分解释了哪些功能包含在两个版本中,哪些功能仅在查看器版本中可用。

XFINIUM.PDF 完全由 C# 编写,是完全托管代码。它以免版税的方式向每位开发者授权,允许您自由发布您的程序,而无需承担任何其他费用。

生成器版本和查看器版本有什么区别?

生成器版是查看器版的一个子集。生成器版提供用于创建和编辑 PDF 的 PDF 功能,而查看器版则在生成器版的基础上增加了 PDF 渲染功能。查看器版可将 PDF 页面转换为 RAW、BMP、GIF、JPG、PNG 和 TIFF 图像。

XFINIUM.PDF 规范

一些重要功能包括

安全

  • 用户和所有者密码
  • 文件访问权限
  • 40 位和 128 位 RC4 加密
  • 128 位和 256 位 AES 加密
  • 内容编辑
  • 禁用文本复制/粘贴

数字签名

  • 使用 X509 证书批准和认证数字签名
  • 使用 SHA256 / SHA384 / SHA512 的基本 CMS 和 PAdES 数字签名
  • 签名时间戳
  • 数字签名中包含的 OCSP 和 CRL 信息
  • 文件安全存储
  • 文件时间戳
  • 最低信用等级 (长期验证) 启用数字签名
  • 将现有签名解码为 ASN.1 对象
  • 从数字签名中提取证书
  • 保存 PDF 文档的签名副本

条形码

  • 内置矢量条形码引擎,无需条形码图像或条形码字体
  • 单维条形码

    • 通用条形码Codabar, Code 11, Code 25, Code 25 Interleaved, Code 39, Code 39 Extended, Code 93, Code 93 Extended, Code 128 A, Code 128 B, Code 128 C, COOP 25, Matrix 25, MSI/Plessey
  • 药品条形码代码 32、Pharmacode、PZN (医药中心编号)
  • 双维条形码

    • DataMatrix, QR, PDF417, Micro PDF417, Codablock F, Code 16K

内容提取

  • 提取带有片段级和字形级位置信息的文本
  • 将文本提取为单词,并在单词级和字形级提供位置信息
  • 从用户定义的区域提取文本和单词
  • 提取图像,包括以像素为单位的图像大小、每像素比特、色彩空间、图像在 PDF 页面上的位置、图像在 PDF 页面上的大小、图像的水平和垂直分辨率等图像信息

低级 COS 应用程序接口

  • 添加、编辑和删除 COS 对象
  • 支持的 COS 对象:字符串、数字、名称、布尔值、空值、数组、字典和流

PDF 渲染 (仅限查看器版本)

  • 将 PDF 页面渲染为图像:RAW、BMP、GIF、JPG、PNG 和 TIFF RAW 图像的 ARGB、RGBA、BGRA、RGB、BGR 和灰度字节布局
  • 将 PDF 转换为多页 TIFF (彩色/灰度/黑白 CCITT G4)

IronPDF 的主要功能

IronPDF .NET PDF 库是开发人员,尤其是 C# 程序员梦寐以求的工具。有了这个神奇的工具,你可以轻松地为 .NET 构建一个核心 PDF 库。

IronPDF 使用 .NET Chromium 引擎将 HTML 页面转换为 PDF 文件。使用 HTML to PDF,无需使用复杂的 API 来定位或设计 PDF。IronPDF 支持标准的在线文档,包括 HTML、ASPX、JS、CSS 和图片。

您还可以使用 HTML5、CSS、JavaScript 和图片来开发 .NET PDF 库。PDF 可以轻松编辑、加盖印章并添加页眉和页脚。阅读 PDF 文本和提取图形也变得轻而易举。

下载IronPDF 并开始在您的 .NET 项目中使用它。

IronPDF C# 库的突出功能

以下是一些主要功能:

制作 PDF (HTML 转 PDF)

  • HTML4/5、CSS 和 JavaScript 均可用于创建 PDF 文档。
  • 使用自定义网络登录凭证、用户代理、代理服务器、cookie、HTTP 标头和表单变量加载 URL,以便在 HTML 登录表单后进行登录。

无需使用 Adobe Acrobat 即可编辑现有 PDF 文档

  • 应读取并填写表格字段中的数据。
  • 从 PDF 文件中提取图形和文本。
  • 可以用新的 HTML 内容更新当前的任何 PDF 页面。
  • 页眉和页脚应符合逻辑或 HTML 格式。

可操作现有 PDF 文档

  • 可加载和解析现有的 PDF 文档。
  • 可以合并和分离 PDF 文档中的内容。

  • 添加页眉、页脚、注释、书签、水印、文本和图像资产,以及文本和图像资产。

从各种文件格式进行转换

  • ASPX WebForms - 将 ASP.NET 网络表格转换为可打印的 PDF,只需三行代码即可在浏览器中查看。
  • 在文档中将 HTML 转换为 PDF。
  • 自定义 "基本 URL",允许从互联网上的任何地方访问资产文件。
  • 虚拟视口允许响应式设计 (宽度和高度).

  • 接受以任何主要文件格式编码的 HTML 文件 (默认为 UTF-8).

打印并保存

  • 文件、二进制数据和 MemoryStreams 都可以保存和加载。
  • 电视或电脑屏幕 CSS 打印介质类型。
  • 通过将 PDF 文件转换为 PrintDocument 对象,无需 Adobe Acrobat 即可打印 PDF 文件 (代码最少).
  • 可导出包含 API 成功信息和源代码中调试故障信息的官方日志文件。

IronPDF 可用于几乎所有与 C# 兼容的操作系统和框架,包括以下操作系统和框架:

  • .NET Core 2.1、3.0、3.1、.NET 6 和 5
  • 符合 .NET 标准 2.0,实现通用兼容性
  • Azure
  • AWS
  • Docker
  • Linux

  • Windows

IronPDF C# 库安装

下载和安装 IronPDF 库有四种方法。具体如下

1.使用 Visual Studio

2.开发人员命令提示符

3.直接下载 NuGet 软件包

4.下载 IronPDF .DLL 库

使用 Visual Studio

Visual Studio 提供了 NuGet 包管理器,用于在项目中安装 NuGet 包。你可以通过 "项目菜单 "或右键单击 "解决方案资源管理器 "中的项目来访问它。这两个选项的截图如图 1 和图 2 所示。

使用 Visual Studio 中的项目菜单访问 NuGet 包管理器

图 1.在 Visual Studio 中使用项目菜单访问 NuGet 包管理器

在 Visual Studio 中使用上下文菜单访问 NuGet 包管理器

图 2.在 Visual Studio 中使用上下文菜单访问 NuGet 包管理器

选择后,浏览 IronPDF 软件包并安装,如下图所示。

使用 Visual Studio 中的 NuGET 包管理器安装 IronPDF 库

图 3.使用 Visual Studio 中的 NuGET 包管理器安装 IronPDF 库

使用开发人员命令提示符

下载和安装 IronPDF C# 库的另一种方法是使用以下步骤,通过开发人员命令提示符安装 IronPDF NuGet 包

  • 打开开发人员命令提示符(通常位于 Visual Studio 文件夹下
  • 键入以下命令
    :ProductInstall
  • 按回车键
  • 这将下载并安装软件包

  • 重新加载 Visual Studio 项目并开始使用它

直接下载 NuGet 软件包

下载和安装 IronPDF 的第三种方法是按照以下步骤操作。可以直接访问 NuGet 网站并下载软件包。步骤如下

通过下载库安装 IronPDF

您可以直接从以下地址下载 IronPDF .DLL 文件 网站.

从 IronPDF 网站下载 IronPDF 库 DLL

图 4.从 IronPDF 网站下载 IronPDF 库 DLL

通过以下步骤在项目中引用该库:

  • 右键单击解决方案资源管理器中的解决方案
  • 选择引用
  • 浏览 IronPDF.dll 库
  • 点击确定

全部完成! IronPDF 已下载、安装并准备就绪。不过,在此之前,我们应该先安装 XFINIUM.PDF API。

XFINIUM.PDF 安装

在 .NET Core 中,我们可以将 Xfinium PDF 安装为 cake addin 或 cake tool。

// 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 Tool

#tool nuget:?package=Xfinium.Pdf.NetCore&version=10.2.0

接下来,让我们深入了解 IronPDF 和 XXFINIUM.PDF 之间的比较。

在 .NET Core 中创建简单的 PDF 文档

在当今世界,软件开发人员必须知道如何使用 C# 代码动态创建 PDF 文件,因为几乎所有项目都需要这样做。您可能出于各种原因需要创建 PDF 文件,例如根据用户输入生成报告、将用户文本保存为 PDF、提取 HTML 信息并将其转换为 PDF 等等。

这两个库都包含将 HTML 网页转换为 PDF 的功能。让我们逐一看看每个库的代码。

使用 IronPDF

IronPDF 有多种创建 PDF 文件的方法。

将现有 URL 转换为 PDF

IronPDF 可以轻松地从现有 URL 将 HTML 转换为 PDF 文档。对 JavaScript、图像、表单和 CSS 都提供了高度支持。

以下代码中使用了 IronPDF,可直接从网站地址创建 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 输入字符串到 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='icons/iron.png'>", @"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='icons/iron.png'>", @"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='icons/iron.png'>", "C:\site\assets\")
AdvancedPDF.SaveAs("html-with-assets.pdf")
VB   C#

使用 XFINIUM.PDF

使用 XFINIUM.PDF 创建空白 PDF 文档只需三行代码:一行创建文档,一行创建页面,另一行保存文档。

PdfFixedDocument document = new PdfFixedDocument();
PdfPage page = document.Pages.Add();
document.Save("empty.pdf");
PdfFixedDocument document = new PdfFixedDocument();
PdfPage page = document.Pages.Add();
document.Save("empty.pdf");
Dim document As New PdfFixedDocument()
Dim page As PdfPage = document.Pages.Add()
document.Save("empty.pdf")
VB   C#

要在上述文档中添加文本内容,还需要三行代码:一行用于创建字体以绘制文本,一行用于创建笔刷和设置文本颜色,另一行用于在页面上实际绘制文本和图形。

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);
document.Save("helloworld.pdf");
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);
document.Save("helloworld.pdf");
Dim document As New PdfFixedDocument()
Dim page As PdfPage = document.Pages.Add()
' Create a standard font with Helvetica face and 24 point size
Dim helvetica As New PdfStandardFont(PdfStandardFontFace.Helvetica, 24)
' Create a solid RGB red brush.
Dim brush As New PdfBrush(PdfRgbColor.Red)
' Draw the text on the page.
page.Graphics.DrawString("Hello World", helvetica, brush, 100, 100)
document.Save("helloworld.pdf")
VB   C#

我们的对象模型与 PDF 标准非常相似。这样,您就可以在此基础上轻松构建复杂的抽象概念,如流程文档。

使生成的 PDF 文件可填充

使用 XFINIUM.PDF

XFINIUM.PDF 库既能创建新的 PDF 表单,也能填充现有的 PDF 表单。

PDF 规范中支持的每种表单字段都由相应的类表示:

  • PdfTextBoxField - 文本框字段
  • PdfCheckBoxField - 复选框
  • PdfRadioButtonField - 单选按钮集
  • PdfComboboxField - 组合框
  • PdfListboxField - 列表框
  • PdfPushbuttonField - 按钮

  • PdfSignatureField - 签名字段

字段的名称及其在页面上的位置是构建表单字段所需的唯一信息。创建字段对象后,必须先将其添加到页面,然后才能指定其他属性。

PdfTextBoxField firstNameTextBox = new PdfTextBoxField("firstname");
pdfpage.Fields.Add(firstNameTextBox);
firstNameTextBox.Widgets [0].VisualRectangle = 
    new PdfVisualRectangle(150, 45, 200, 20);
PdfTextBoxField firstNameTextBox = new PdfTextBoxField("firstname");
pdfpage.Fields.Add(firstNameTextBox);
firstNameTextBox.Widgets [0].VisualRectangle = 
    new PdfVisualRectangle(150, 45, 200, 20);
Dim firstNameTextBox As New PdfTextBoxField("firstname")
pdfpage.Fields.Add(firstNameTextBox)
firstNameTextBox.Widgets (0).VisualRectangle = New PdfVisualRectangle(150, 45, 200, 20)
VB   C#

如果在 PdfFixedDocument 对象中加载了现有的 PDF 表单,则可对其进行填充。加载表单后,文档的字段集合会自动填充表单中定义的字段。字段可通过索引或名称在集合中定位,并通过设置 PdfField 基类中定义的通用值属性或每种字段类型定义的特定值属性来填充。

PdfFixedDocument document = new PdfFixedDocument("form.pdf");
(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;
document.Save("form_filled.pdf");
PdfFixedDocument document = new PdfFixedDocument("form.pdf");
(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;
document.Save("form_filled.pdf");
Dim document As New PdfFixedDocument("form.pdf")
TryCast(document.Form.Fields ("firstname"), PdfTextBoxField).Text = "John"
TryCast(document.Form.Fields ("lastname"), PdfTextBoxField).Value = "Doe"
TryCast(document.Form.Fields ("sex").Widgets (0), PdfRadioButtonWidget).Checked = True
TryCast(document.Form.Fields ("firstcar"), PdfComboBoxField).SelectedIndex = 0
TryCast(document.Form.Fields ("secondcar"), PdfListBoxField).SelectedIndex = 1
TryCast(document.Form.Fields ("agree"), PdfCheckBoxField).Checked = True
document.Save("form_filled.pdf")
VB   C#

使用 IronPDF

让我们看看如何使用 IronPDF C# 库创建可填充 PDF。

// PM> Install-Package IronPdf
using IronPdf;

// Step 1.  Creating a PDF with editable forms from HTML using form and input tags

var FormHtml = @"
<html>
    <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='' >
        </form>
    </body>
</html>";

IronPdf.ChromePdfRenderer Renderer = new IronPdf.ChromePdfRenderer();
Renderer.RenderingOptions.CreatePdfFormsFromHtml = true;
Renderer.RenderHtmlAsPdf(FormHtml).SaveAs("BasicForm.pdf");

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

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

//Set and Read the value of the "lastname" field
IronPdf.Forms.FormField LastNameField = FormDocument.Form.GetFieldByName("lastname");
LastNameField.Value = "Mouse";
Console.WriteLine("LastNameField value: {0}", LastNameField.Value);

FormDocument.SaveAs("FilledForm.pdf");
// PM> Install-Package IronPdf
using IronPdf;

// Step 1.  Creating a PDF with editable forms from HTML using form and input tags

var FormHtml = @"
<html>
    <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='' >
        </form>
    </body>
</html>";

IronPdf.ChromePdfRenderer Renderer = new IronPdf.ChromePdfRenderer();
Renderer.RenderingOptions.CreatePdfFormsFromHtml = true;
Renderer.RenderHtmlAsPdf(FormHtml).SaveAs("BasicForm.pdf");

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

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

//Set and Read the value of the "lastname" field
IronPdf.Forms.FormField LastNameField = FormDocument.Form.GetFieldByName("lastname");
LastNameField.Value = "Mouse";
Console.WriteLine("LastNameField value: {0}", LastNameField.Value);

FormDocument.SaveAs("FilledForm.pdf");
' PM> Install-Package IronPdf
Imports IronPdf

' Step 1.  Creating a PDF with editable forms from HTML using form and input tags

Private FormHtml = "
<html>
    <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='' >
        </form>
    </body>
</html>"

Private Renderer As New IronPdf.ChromePdfRenderer()
Renderer.RenderingOptions.CreatePdfFormsFromHtml = True
Renderer.RenderHtmlAsPdf(FormHtml).SaveAs("BasicForm.pdf")

' Step 2. Reading and Writing PDF form values.
Dim FormDocument = PdfDocument.FromFile("BasicForm.pdf")

'Set and Read the value of the "firstname" field
Dim FirstNameField = FormDocument.Form.GetFieldByName("firstname")
FirstNameField.Value = "Minnie"
Console.WriteLine("FirstNameField value: {0}", FirstNameField.Value)

'Set and Read the value of the "lastname" field
Dim LastNameField As IronPdf.Forms.FormField = FormDocument.Form.GetFieldByName("lastname")
LastNameField.Value = "Mouse"
Console.WriteLine("LastNameField value: {0}", LastNameField.Value)

FormDocument.SaveAs("FilledForm.pdf")
VB   C#

首先,我们在以下代码中创建一个带有 HTML 格式标记的表单。然后,我们将其保存为 PDF 文档。我们在第 2 步开始读写 PDF 表单值。有了字段名称,就可以找到表单字段。IronPDF 中提供了 GetFieldByName 函数。然后设置所选字段的值,并保存新填充的表单。

PDF 文件的数字签名

在现代社会,许多人都是远程工作。填写和签署表格、发送文件和处理文件只是企业每天需要完成的一些主要活动。其中一项主要活动就是签署 PDF 文档、PDF 档案和 PDF 表单,以替代纸质文档。随着公司寻求签署协议和合同以及在线共享 PDF 表单的方法,数字签名已变得必不可少。

使用 XFINIUM.PDF

PDF 文件中的签名字段用于应用数字签名 (PdfSignatureField 类).虽然签名字段是出现在文档某一页上的表单字段,但数字签名是用来签署整个文档的,而不仅仅是那一页。

签名过程从使用 PdfDigitalSignature 对象设置签名字段的签名属性开始。由于签名是基于 PDF 文件的实际二进制布局,因此它是在保存文档时形成的。

PdfDigitalSignature 类是所有 XFINIUM 数字签名的基础。

有多种签名类可供选择:

  • PdfCmsDigitalSignature - 基于 CMS 标准的数字签名 (继承于 PdfDigitalSignature)
  • PdfPadesDigitalSignature - 实现 PADES 标准的数字签名 (继承于 PdfCmsDigitalSignature)
  • PdfInteractiveCmsDigitalSignature - 基于内容管理系统标准的数字签名,可使用硬件签名智能卡创建数字签名 (继承于 PdfDigitalSignature)
  • PdfInteractivePadesDigitalSignature - 实现 PADES 标准的数字签名,可使用硬件签名智能卡创建数字签名 (继承于 PdfInteractiveCmsDigitalSignature)

  • PdfDocumentTimeStamp - 文档级时间戳 (继承于 PdfDigitalSignature)

使用 IronPDF

开发人员经常询问如何利用 IronPDF 和 C# 以编程方式在 PDF 中添加签名。这对开发人员来说有多种含义:

  • 从图像文件中为现有 PDF 文件添加图形数字签名图像。
  • 通过加密签名确认 PDF 文件未被篡改。

  • 为已加密签名的 PDF 添加人工手写签名图标。

第一种方法是在已存在的 PDF 页面上加盖签名 PNG 图章。它可以用作签名或公司印章。鼓励使用不透明度。只需几行代码即可完成该程序。

// open an existing PDF document or create a new one
PdfDocument Pdf = PdfDocument.FromFile(@"C:\Path\To\ASPX to PDF.pdf");
var SignatureStamp = new HtmlStamp() { Html = "<img src='signature.png' />", Width = 150, Height = 50, Bottom = 300, Left=85, ZIndex = HtmlStamp.StampLayer.OnTopOfExistingPDFContent };
Pdf.StampHTML(SignatureStamp,1);
Pdf.SaveAs(@"C:\Path\To\ASPX to PDF.pdf");
// open an existing PDF document or create a new one
PdfDocument Pdf = PdfDocument.FromFile(@"C:\Path\To\ASPX to PDF.pdf");
var SignatureStamp = new HtmlStamp() { Html = "<img src='signature.png' />", Width = 150, Height = 50, Bottom = 300, Left=85, ZIndex = HtmlStamp.StampLayer.OnTopOfExistingPDFContent };
Pdf.StampHTML(SignatureStamp,1);
Pdf.SaveAs(@"C:\Path\To\ASPX to PDF.pdf");
' open an existing PDF document or create a new one
Dim Pdf As PdfDocument = PdfDocument.FromFile("C:\Path\To\ASPX to PDF.pdf")
Dim SignatureStamp = New HtmlStamp() With {
	.Html = "<img src='signature.png' />",
	.Width = 150,
	.Height = 50,
	.Bottom = 300,
	.Left=85,
	.ZIndex = HtmlStamp.StampLayer.OnTopOfExistingPDFContent
}
Pdf.StampHTML(SignatureStamp,1)
Pdf.SaveAs("C:\Path\To\ASPX to PDF.pdf")
VB   C#

下面的代码使用 .pfx 和 .p12 X509Certificate2 数字证书对 PDF 进行加密签名,只需一行代码即可轻松创建。

// 123456 below represents the signature password
new IronPdf.PdfSignature("CertificateFile.p12", "123456").SignPdfFile("ASPX to PDF.pdf");
// 123456 below represents the signature password
new IronPdf.PdfSignature("CertificateFile.p12", "123456").SignPdfFile("ASPX to PDF.pdf");
' 123456 below represents the signature password
Call (New IronPdf.PdfSignature("CertificateFile.p12", "123456")).SignPdfFile("ASPX to PDF.pdf")
VB   C#

这个更高级的示例允许将 .pfx / .p12 X509Certificate2 数字 ID 签名方法与手写签名扫描结合起来。

var Signature = new IronPdf.PdfSignature("Iron.pfx", "123456");
PdfDocument doc = Renderer.RenderHtmlAsPdf("<h1>Testing 2048 bit digital security</h1>");
// Step 3. 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";
Signature.LoadSignatureImageFromFile("handwriting.png");
doc.SignPdfWithDigitalSignature(Signature);
doc.SaveAs("ASPX to PDF.pdf");
var Signature = new IronPdf.PdfSignature("Iron.pfx", "123456");
PdfDocument doc = Renderer.RenderHtmlAsPdf("<h1>Testing 2048 bit digital security</h1>");
// Step 3. 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";
Signature.LoadSignatureImageFromFile("handwriting.png");
doc.SignPdfWithDigitalSignature(Signature);
doc.SaveAs("ASPX to PDF.pdf");
Dim Signature = New IronPdf.PdfSignature("Iron.pfx", "123456")
Dim doc As PdfDocument = Renderer.RenderHtmlAsPdf("<h1>Testing 2048 bit digital security</h1>")
' Step 3. 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"
Signature.LoadSignatureImageFromFile("handwriting.png")
doc.SignPdfWithDigitalSignature(Signature)
doc.SaveAs("ASPX to PDF.pdf")
VB   C#

定价和许可

XFINIUM.PDF 定价和许可

每个软件包都有两个版本:生成器版本(提供 PDF 制作和编辑功能)和查看器版本(包含生成器版本的所有功能,以及 PDF 渲染和 PDF 查看功能)。

  • 每个开发人员都有自己的 Xfinium PDF 库许可证。每个为 XFINIUM 编写代码的开发人员都需要获得该 PDF 文件库的许可证。
  • 作为许可证的一部分,XFINIUM.PDF 可以免版税发送到不限数量的台式 PC 和服务器上。

  • 一年的 "协助订阅 "可提供一年的免费升级和技术支持。

根据不同的套餐,每年的价格从 290 美元到 872 美元不等。

IronPDF 定价和许可

另一方面,IronPDF 是一个 C# PDF 库。它可以免费用于开发,也可以随时授权用于商业用途。单个项目许可、单个开发人员、机构和跨国组织,以及 SaaS 和 OEM 再分发都可以使用。所有许可证均附带 30 天退款保证、一年的软件支持和升级、开发/分期/生产有效性以及永久许可证。 (一次性购买).精简版软件包的价格为 $749。IronPDF 产品没有经常性费用。

结论

Iron PDF 库不依赖于专有的应用程序接口,因此可以更轻松地创建 PDF 文档。"HTML-To-PDF" 可将 HTML、JS、CSS、JPG、PNG、GIF 和 SVG 等开放标准文档类型转换为像素完美的 PDF。换句话说,它建立在开发人员现有才能的基础上。它允许用户下载文档、通过电子邮件发送或保存到云端,并制作账单、报价、报告、合同和其他文书工作。它可与 ASP.NET、ASP.NET Core、Web 表单、MVC、.NET Framework 和 .NET Core Web API 配合使用。

XFINIUM.PDF 库具有广泛的功能,适合新手和高级 PDF 开发人员使用。无论您是需要制作简单的报告、填写 PDF 表单、构建 PDF 作品集、编辑 PDF 文件中的敏感信息,还是将 PDF 文件转换为多页 TIFF 图像,XFINIUM.PDF 库都能为您提供所需的工具。由于基本对象模型符合 PDF 规范,因此您可以完全控制生成的 PDF 文件。XFINIUM.PDF 代码无需修改即可在所有支持的平台上编译。XFINIUM.PDF 套件可为您提供帮助。

XFINIUM.PDF 许可证有两个版本:生成器和查看器,起价分别为 290 美元和 387 美元。这比 IronPDF 便宜一些,后者的精简版起价为 $749。IronPDF 值得一试,因为它同时提供单用户和多用户许可证,而 XFINIUM.PDF 只提供单用户许可证--这意味着你需要为每个开发人员都提供一个许可证。另一方面,IronPDF 提供的专业许可证起价为 799 美元,可用于无限数量的用户。

与 XFINIUM.PDF 相比,使用 IronPDF 可以更轻松地处理 PDF 文件。IronPDF 使用较少的代码行进行复杂的操作,这有助于减轻程序员的工作量。

Iron Software 公司还为所有客户提供了只需点击两下就能获得整套软件包的选择。这意味着,只需支付 Iron 软件套件中两个程序库的价格,您就可以获得全部五个程序库,以及对所有程序库的不间断支持。

< 前一页
IronPDF 和 SautinSoft PDF Focus 的比较
下一步 >
IronPDF与GrapeCity PDF Viewer的比较

准备开始了吗? 版本: 2024.9 刚刚发布

免费NuGet下载 总下载量: 10,731,156 查看许可证 >