产品比较

IronPDF与Apitron PDF Kit对比

发布 2022年十二月11日
分享:

在 C# 中,处理 PDF 文件对开发人员来说是一项挑战。 在为此类文件创建内容时需要考虑很多因素,而将内容从不同格式转换为 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 组件可用于创建跨多个平台的移动、桌面、网络、Windows 和云应用程序。

使用该 PDF SDK,您将能够

  • 提取、修改和添加图形 (文字、图像、图画)
  • 分割或合并 PDF 文档
  • 填写或创建受密码保护的 PDF 表单,支持 FDF
  • 创建带有可选内容组的多层 PDF 文档 ( OCG )
  • 从文档中添加或删除字段
  • 使用从右向左或双向文字创建页面内容
  • 检查文档中的资源 - 已定义的字体、嵌入文件
  • 在 PDF 文档上进行数字签名并检查现有签名

IronPDF 的主要功能

开发人员,尤其是 C# 程序员,一定会对 IronPDF for .NET 库爱不释手。 有了这款神奇的工具,您就可以轻松构建.NET Core PDF 处理程序。

IronPDF for .NET 使用 .NET Chromium 引擎更改 HTML 页面 (代码或 URL 形式) 到 PDF 文件。 完全没有必要使用复杂的应用程序接口来定位导航对象或从 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 标准 2.0,实现通用兼容性
  • Azure、AWS、Docker、Linux、Windows

    文章的其余部分如下:

  1. IronPDF 安装
  2. Apitron PDF 套件安装
  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
  • 按回车键
  • 这将下载并安装软件包
  • 重新加载项目并开始使用

1.3.直接下载 NuGet 软件包

也可以直接访问 NuGet 网站并下载软件包来安装 IronPDF。 步骤如下

  • 导航至 https://www.nuget.org/packages/IronPdf/
  • 选择下载软件包
  • 双击下载的软件包
  • 软件包将被安装
  • 重新加载 Visual Studio 项目并开始使用它

    IronPDF 已下载并可使用。 不过,在此之前,我们应该先安装 Apitron PDF 库。

2.Apitron PDF 套件安装

对于 .NET Core 应用程序,我们可以使用 NuGet 包管理器安装 Apitron,也可以从以下网址下载并安装 Apitron NuGet 直接访问网站。

  • 像在 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

按 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 的方法。 让我们来看看两个重要的问题。

将现有 URL 转换为 PDF

IronPDF 可轻松将任何 URL 转换为 PDF。 以下代码有助于将 URL 转换为 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='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");
IRON VB CONVERTER ERROR developers@ironsoftware.com
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);
}
IRON VB CONVERTER ERROR developers@ironsoftware.com
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");
IRON VB CONVERTER ERROR developers@ironsoftware.com
VB   C#

输出结果如下

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 Fit 中,可以使用 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 套件

使用 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 套件定价与许可

目前使用的许可证制度有两种--现代和传统。 如果您已经拥有许可证,则传统许可证方案将一直有效,直到您的许可证到期。 之后,您必须联系客户支持部门进行过渡。 现代许可计划仅适用于新客户。

根据现代计划,许可证分为三个等级:

  • 评估 - 使用全功能产品的三个月评估期。 只需从 NuGet 下载软件包并开始开发即可。
  • 社区 - 在非商业项目中使用功能齐全的产品,无需支付任何费用。 需要批准。
  • 商业 - 以上未说明的任何用例。 价格取决于使用模式。

    有关购买的详细信息,您可以 联系 Apitron 销售代表.

结论

IronPDF 库可从 HTML、JS、CSS、JPG、PNG、GIF 和 SVG 等文档类型创建像素完美的 PDF。 Chromium 引擎可帮助渲染 HTML 文件或 URL,从而输出完美的 PDF 文件。

Apitron 可让您使用固定布局 API 创建 PDF,其实现与 PDF 规范 100% 兼容。 作为一种类似于 HTML 和 CSS 的样式驱动内容生成方法,这种固定布局 API 可让您在几分钟内创建出令人惊叹的报告、账单、目录等内容。 它还支持创建 XML 模板。

Apitron PDF 的许可价格不在其网站上提供。您必须联系支持人员,根据您的使用情况获得报价。 另一方面,IronPDF 在其网站上显示了非常清晰的许可套餐。这使得 IronPDF 从众多竞争者中脱颖而出,用户可以根据自己的需求做出明智的选择。

与 Apitron PDF 相比,使用 IronPDF 可以更轻松地处理 PDF 文件。 IronPDF 允许用户编写更少行的代码来完成具有挑战性的 PDF 工作。 IronPDF 提供多种方法从多种文件类型生成 PDF,而 Apitron 只能将 XML 文档转换为 PDF 文档。 与 Apitron 相比,IronPDF 无需添加任何技术选项即可实现完美输出。

Iron Software 的所有客户都可以选择以购买两套产品的价格购买公司的全部五套产品。 尝试 免费试用 30 天 以测试其全部功能。 购买全套 Iron Software 产品 这里.

< 前一页
Telerik HTML to PDF生成器与IronPDF
下一步 >
IronPDF与GroupDocs的比较

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

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