IronPDF 与 XFINIUM.PDF:.NET 平台 HTML 转 PDF 库对比
IronPDF 擅长 HTML 转 PDF,它使用 Chromium 内核,并完全支持 CSS 和 JavaScript。相比之下,XFINIUM.PDF 专注于底层 PDF 操作,不进行原生 HTML 渲染,因此 IronPDF 更适合在 .NET 应用程序中生成基于 Web 的现代 PDF 文件。
现代科技为开发者提供了更智能的解决方案,自动化推动了软件开发流程。 长期以来,处理C# PDF 文件一直是开发人员面临的一项挑战。 创建 PDF 文件内容时必须考虑多种因素,将不同格式的内容转换为 PDF时更是如此。 这些挑战现在可以通过各种库来解决,这些库旨在帮助用户阅读、编写、创建和转换各种格式的 PDF 文件。
本文比较了两个适用于.NET和.NET Core开发人员的常用 PDF 库:
- XFINIUM.PDF 库
IronPDF 和 XFINIUM.PDF 都提供了在 .NET 和 .NET Core 中创建、操作和打印 PDF的方法。 您可以查看以下对两个库及其各自的PDF 转换和处理功能的比较,从而做出明智的决定。
首先,让我们了解一下这两个库的功能,然后再进行比较。
XFINIUM.PDF 库有哪些特点?
XFINIUM.PDF 库是一个跨平台的 PDF 开发工具,既适用于初级 PDF 开发人员,也适用于高级 PDF 开发人员。 它允许您创建报告、填写 PDF 表单、构建 PDF 作品集、从 PDF 报告中删除敏感数据,或将 PDF 报告转换为多页 TIFF 图像。
XFINIUM.PDF 提供两个版本:生成器版本,包括 PDF 生成和编辑功能;查看器版本,增加了PDF 渲染和PDF 查看功能。
XFINIUM.PDF 完全使用 C# 编写,是完全托管的代码。 它按开发者授权,无需支付版税即可分发,让您可以免费分发您的程序。
生成器版和查看器版之间有什么区别?
生成器版是查看器版的一个子集。 它提供创建和编辑 PDF 的 PDF 功能,而查看器版本则增加了PDF 渲染功能。 查看器版可以将 PDF 页面转换为 RAW、BMP、GIF、JPG、PNG 和 TIFF 图像。
XFINIUM.PDF 规范
关键特性包括:
安全性
- 文档访问权限
- 40 位和 128 位 RC4 加密
- 128 位和 256 位 AES 加密 -内容编辑
- 禁用文本复制/粘贴
数字签名
- CMS 和 PAdES 签名采用 SHA256/384/512
- 签名时间戳
- 签名中包含 OCSP 和 CRL 信息
- 文档安全存储
- 文档时间戳
- LTV启用数字签名
- 将签名解码为 ASN.1 对象
- 从签名中提取证书 -保存已签名的PDF副本
条码
- 内置矢量条形码引擎
- 一维条码:
- Codabar、Code 11、Code 25、Code 39/93/128
- 药品:代码 32,药品代码,PZN
- 二维条码:
DataMatrix、QR、PDF417、微型 PDF417
如需更高级的条形码功能,请参考Ironbarcode 文档,其中提供了完整的条形码生成和读取功能。
内容提取
- 提取文本,并标明单词位置
- 从用户定义的区域提取 -提取带有元数据的图像
低级 COS API
- 添加、编辑和删除 COS 对象 支持的类型:字符串、数字、名称、布尔值、空值、数组、字典、流
PDF 渲染(仅限查看器版)
-将页面渲染为图像:RAW、BMP、GIF、JPG、PNG、TIFF
- ARGB、RGBA、BGRA、RGB、BGR 和灰度布局 使用 CCITT G4将 PDF 转换为多页 TIFF
IronPDF的主要特点是什么?
IronPDF .NET PDF 库简化了 C# 程序员的 PDF 开发。 借助此工具,您可以轻松地为 .NET 构建核心 PDF 库。
IronPDF 使用.NET Chromium 引擎将 HTML 页面转换为 PDF 文件。 使用HTML to PDF,您无需复杂的 API 即可定位或设计 PDF。 支持标准网页文档,包括HTML、ASPX、JS、CSS 和图像。
您可以使用HTML5、CSS、JavaScript 和图像来开发 .NET PDF 库。 PDF 文件可以进行编辑、添加印章,并通过页眉和页脚进行改进。 该库能够高效地读取 PDF 文本并提取图形。
免费下载 IronPDF,并立即在您的 .NET 项目中使用。
IronPDF C# 库的突出特点
关键特性包括:
生成 PDF(HTML 到 PDF)
- 支持HTML4/5、CSS 和 JavaScript
- 加载包含网络凭据、用户代理、代理服务器、 Cookie和 HTTP 标头的 URL
编辑现有PDF文档
阅读并填写表单字段 提取图形和文本 -使用新的 HTML 内容更新页面 -添加逻辑或 HTML 页眉/页脚
操作PDF文档
转换各种文件格式
- ASPX WebForms — 只需三行代码即可转换 将 HTML 文件转换为 PDF
- 用于资源访问的自定义基本 URL
- 用于响应式设计的虚拟视口
- 支持主流文件编码(默认UTF-8 )
打印并保存
- 用于打印的CSS 媒体类型 无需 Adobe Acrobat 即可打印 PDF 文件 -导出 API 日志以进行调试
IronPDF 支持所有主流操作系统和框架:
如何安装 IronPDF C# 库?
您可以通过以下四种方式下载并安装 IronPDF:
- 使用 Visual Studio
- 开发人员命令提示符
- 直接下载NuGet 包
- 下载 IronPDF .DLL 库
使用Visual Studio
Visual Studio 提供了 NuGet 包管理器,用于在项目中安装包。 通过"项目"菜单或在"解决方案资源管理器"中右键单击项目来访问它。

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

图 2。使用 Visual Studio 中的上下文菜单访问 NuGet 包管理器
选定后,浏览并安装 IronPDF 软件包。

图 3。使用 Visual Studio 中的 NuGET 包管理器安装 IronPDF 库
使用开发人员命令提示
通过开发者命令提示符安装IronPDF NuGet 包:
- 打开开发者命令提示符
键入以下命令:
nuget install IronPdfnuget install IronPdfSHELL- 按回车键
- 该软件包下载并安装
- 重新加载 Visual Studio 项目
直接下载 NuGet 包
直接从 NuGet 下载并安装 IronPDF:
- 前往IronPdf NuGet 页面
- 选择下载包
- 双击下载的软件包 该软件包用于安装
- 重新加载 Visual Studio 项目
通过下载库安装 IronPDF
直接从IronPDF 下载页面下载 IronPDF .DLL 文件。

图 4。从 IronPDF 网站下载 IronPDF 库 DLL
在项目中引用该库:
- 在解决方案资源管理器中右键单击解决方案。
- 选择引用
- 浏览 IronPDF.dll 库
- 点击确定
IronPDF现在可以使用了。 接下来我们安装 XFINIUM.PDF。
如何安装 XFINIUM.PDF?
在 .NET Core 中,将 Xfinium PDF 安装为 CakePHP 插件或工具:
# Install Xfinium.Pdf.NetCore as a Cake Addin
#addin nuget:?package=Xfinium.Pdf.NetCore&version=10.2.0# Install Xfinium.Pdf.NetCore as a Cake Addin
#addin nuget:?package=Xfinium.Pdf.NetCore&version=10.2.0# Install Xfinium.Pdf.NetCore as a Cake Tool
#tool nuget:?package=Xfinium.Pdf.NetCore&version=10.2.0# Install Xfinium.Pdf.NetCore as a Cake Tool
#tool nuget:?package=Xfinium.Pdf.NetCore&version=10.2.0现在让我们来比较一下 IronPDF 和 XFINIUM.PDF。
如何在.NET Core中创建简单的PDF文档?
软件开发人员必须知道如何使用 C#动态创建 PDF 文件。 您可能需要创建 PDF 文件,例如根据用户输入生成报告、将用户文本保存为 PDF、提取 HTML 信息并将其转换为 PDF等等。
这两个库都可以将HTML网页转换为PDF 。 让我们逐一分析每个库的方法。
使用 IronPDF.
IronPDF 提供了多种创建 PDF 文件的方法。
将现有 URL 转换为 PDF.
IronPDF 可以轻松地从现有 URL 将 HTML 转换为 PDF 文档。 完全支持JavaScript 、图像、表单和 CSS。
该实现会自动处理 URL 渲染:
// Create an instance of the ChromePdfRenderer
IronPdf.ChromePdfRenderer Renderer = new IronPdf.ChromePdfRenderer();
// Configure rendering options for better performance
Renderer.RenderingOptions.WaitFor.RenderDelay = 500; // Wait for JavaScript to load
Renderer.RenderingOptions.CssMediaType = IronPdf.Rendering.PdfCssMediaType.Print;
// Render a URL to PDF
using var Pdf = Renderer.RenderUrlAsPdf("___PROTECTED_URL_134___");
// Save the PDF with metadata
Pdf.MetaData.Author = "IronPDF";
Pdf.MetaData.Title = "Website to PDF Conversion";
Pdf.SaveAs("url.pdf");// Create an instance of the ChromePdfRenderer
IronPdf.ChromePdfRenderer Renderer = new IronPdf.ChromePdfRenderer();
// Configure rendering options for better performance
Renderer.RenderingOptions.WaitFor.RenderDelay = 500; // Wait for JavaScript to load
Renderer.RenderingOptions.CssMediaType = IronPdf.Rendering.PdfCssMediaType.Print;
// Render a URL to PDF
using var Pdf = Renderer.RenderUrlAsPdf("___PROTECTED_URL_134___");
// Save the PDF with metadata
Pdf.MetaData.Author = "IronPDF";
Pdf.MetaData.Title = "Website to PDF Conversion";
Pdf.SaveAs("url.pdf");将 HTML 输入字符串转换为 PDF 文件
请看以下代码示例,该示例用于从 HTML 字符串渲染 PDF 页面。 你可以单独使用 HTML,也可以将其与 CSS、图片和 JavaScript 结合使用:
// Create an instance of the ChromePdfRenderer
var Renderer = new IronPdf.ChromePdfRenderer();
// Configure rendering options
Renderer.RenderingOptions.MarginTop = 50; // millimeters
Renderer.RenderingOptions.MarginBottom = 50;
Renderer.RenderingOptions.CssMediaType = IronPdf.Rendering.PdfCssMediaType.Print;
// Render a simple HTML string to PDF
using var PDF = Renderer.RenderHtmlAsPdf("<h1>Html with CSS and Images</h1>");
// Add document properties
PDF.MetaData.Author = "Development Team";
PDF.MetaData.Keywords = "HTML, PDF, C#";
PDF.MetaData.ModifiedDate = DateTime.Now;
// Save the PDF
PDF.SaveAs("pixel-perfect.pdf");
// Load external HTML assets: images, CSS, and javascript
// An optional BasePath 'C:\site\assets\' is set as the file location to load assets from
using var AdvancedPDF = Renderer.RenderHtmlAsPdf("<img src='icons/iron.png'>", @"C:\site\assets\");
// Apply security settings
AdvancedPDF.Password = "pass123";
AdvancedPDF.SecuritySettings.AllowUserPrinting = IronPdf.Security.PdfPrintSecurity.FullPrintRights;
// Save the advanced PDF with external assets
AdvancedPDF.SaveAs("html-with-assets.pdf");// Create an instance of the ChromePdfRenderer
var Renderer = new IronPdf.ChromePdfRenderer();
// Configure rendering options
Renderer.RenderingOptions.MarginTop = 50; // millimeters
Renderer.RenderingOptions.MarginBottom = 50;
Renderer.RenderingOptions.CssMediaType = IronPdf.Rendering.PdfCssMediaType.Print;
// Render a simple HTML string to PDF
using var PDF = Renderer.RenderHtmlAsPdf("<h1>Html with CSS and Images</h1>");
// Add document properties
PDF.MetaData.Author = "Development Team";
PDF.MetaData.Keywords = "HTML, PDF, C#";
PDF.MetaData.ModifiedDate = DateTime.Now;
// Save the PDF
PDF.SaveAs("pixel-perfect.pdf");
// Load external HTML assets: images, CSS, and javascript
// An optional BasePath 'C:\site\assets\' is set as the file location to load assets from
using var AdvancedPDF = Renderer.RenderHtmlAsPdf("<img src='icons/iron.png'>", @"C:\site\assets\");
// Apply security settings
AdvancedPDF.Password = "pass123";
AdvancedPDF.SecuritySettings.AllowUserPrinting = IronPdf.Security.PdfPrintSecurity.FullPrintRights;
// Save the advanced PDF with external assets
AdvancedPDF.SaveAs("html-with-assets.pdf");有关更高级的 HTML 转 PDF 转换技巧,请参阅HTML 转 PDF 教程。
使用 XFINIUM.PDF
使用 XFINIUM.PDF 创建空白 PDF 文档只需三行代码:创建文档、创建页面、保存:
// Create a new PDF document
PdfFixedDocument document = new PdfFixedDocument();
// Add a page to the document
PdfPage page = document.Pages.Add();
// Save the document as a PDF file
document.Save("empty.pdf");// Create a new PDF document
PdfFixedDocument document = new PdfFixedDocument();
// Add a page to the document
PdfPage page = document.Pages.Add();
// Save the document as a PDF file
document.Save("empty.pdf");添加文本内容需要三行额外的代码:创建字体、创建颜色画笔和绘制文本:
// Create a new PDF document
PdfFixedDocument document = new PdfFixedDocument();
PdfPage page = document.Pages.Add();
// Create a standard font with Helvetica face and 24 point size
PdfStandardFont helvetica = new PdfStandardFont(PdfStandardFontFace.Helvetica, 24);
// Create a solid RGB red brush.
PdfBrush brush = new PdfBrush(PdfRgbColor.Red);
// Draw the text on the page.
page.Graphics.DrawString("Hello World", helvetica, brush, 100, 100);
// Save the document as a PDF file
document.Save("helloworld.pdf");// Create a new PDF document
PdfFixedDocument document = new PdfFixedDocument();
PdfPage page = document.Pages.Add();
// Create a standard font with Helvetica face and 24 point size
PdfStandardFont helvetica = new PdfStandardFont(PdfStandardFontFace.Helvetica, 24);
// Create a solid RGB red brush.
PdfBrush brush = new PdfBrush(PdfRgbColor.Red);
// Draw the text on the page.
page.Graphics.DrawString("Hello World", helvetica, brush, 100, 100);
// Save the document as a PDF file
document.Save("helloworld.pdf");该对象模型与 PDF 标准非常相似。 这种方法在构建复杂抽象概念(例如流程文档)方面具有明显的优势。## 如何创建可填写 PDF 文件
使用 XFINIUM.PDF
XFINIUM.PDF 允许您创建新的 PDF 表单和填写现有的 PDF 表单。
每种 PDF 表单字段类型都有一个对应的类:
PdfTextBoxField– 文本框字段PdfCheckBoxField– 复选框PdfRadioButtonField– 单选按钮集PdfComboboxField– 组合框PdfListboxField– 列表框PdfPushbuttonField– 按钮- PdfSignatureField – 签名字段
要创建表单字段,请指定字段名称和页面位置。 创建字段对象后,将其添加到页面并设置其属性:
// Create a text box field named "firstname"
PdfTextBoxField firstNameTextBox = new PdfTextBoxField("firstname");
// Add the field to a PDF page
pdfpage.Fields.Add(firstNameTextBox);
// Set the position of the field on the PDF page
firstNameTextBox.Widgets[0].VisualRectangle = new PdfVisualRectangle(150, 45, 200, 20);// Create a text box field named "firstname"
PdfTextBoxField firstNameTextBox = new PdfTextBoxField("firstname");
// Add the field to a PDF page
pdfpage.Fields.Add(firstNameTextBox);
// Set the position of the field on the PDF page
firstNameTextBox.Widgets[0].VisualRectangle = new PdfVisualRectangle(150, 45, 200, 20);要填写现有的 PDF 表单,请将其加载到PdfFixedDocument对象中。 文档的字段集合会自动填充。 您可以按索引或名称查找字段,并通过设置值属性来填充它们:
// Load an existing PDF document with forms
PdfFixedDocument document = new PdfFixedDocument("form.pdf");
// Fill form fields with values
(document.Form.Fields["firstname"] as PdfTextBoxField).Text = "John";
(document.Form.Fields["lastname"] as PdfTextBoxField).Value = "Doe";
(document.Form.Fields["sex"].Widgets[0] as PdfRadioButtonWidget).Checked = true;
(document.Form.Fields["firstcar"] as PdfComboBoxField).SelectedIndex = 0;
(document.Form.Fields["secondcar"] as PdfListBoxField).SelectedIndex = 1;
(document.Form.Fields["agree"] as PdfCheckBoxField).Checked = true;
// Save the filled form as a new PDF file
document.Save("form_filled.pdf");// Load an existing PDF document with forms
PdfFixedDocument document = new PdfFixedDocument("form.pdf");
// Fill form fields with values
(document.Form.Fields["firstname"] as PdfTextBoxField).Text = "John";
(document.Form.Fields["lastname"] as PdfTextBoxField).Value = "Doe";
(document.Form.Fields["sex"].Widgets[0] as PdfRadioButtonWidget).Checked = true;
(document.Form.Fields["firstcar"] as PdfComboBoxField).SelectedIndex = 0;
(document.Form.Fields["secondcar"] as PdfListBoxField).SelectedIndex = 1;
(document.Form.Fields["agree"] as PdfCheckBoxField).Checked = true;
// Save the filled form as a new PDF file
document.Save("form_filled.pdf");使用 IronPDF.
以下是如何使用 IronPDF创建可填写 PDF 的方法:
// PM> Install-Package IronPdf
using IronPdf;
using IronPdf.Rendering;
// Step 1. Creating a PDF with editable forms from HTML using form and input tags
var FormHtml = @"
<html>
<head>
<style>
body { font-family: Arial, sans-serif; margin: 40px; }
h2 { color: #333; }
form { background: #f4f4f4; padding: 20px; border-radius: 8px; }
input[type='text'] {
width: 100%;
padding: 8px;
margin: 10px 0;
border: 1px solid #ddd;
border-radius: 4px;
}
input[type='checkbox'] { margin-right: 10px; }
select { width: 100%; padding: 8px; margin: 10px 0; }
</style>
</head>
<body>
<h2>Editable PDF Form</h2>
<form>
First name:<br> <input type='text' name='firstname' value=''> <br>
Last name:<br> <input type='text' name='lastname' value=''>
<br><br>
Email:<br> <input type='text' name='email' value=''>
<br><br>
Subscribe to newsletter: <input type='checkbox' name='newsletter' value='yes'>
<br><br>
Country:
<select name='country'>
<option value='usa'>United States</option>
<option value='uk'>United Kingdom</option>
<option value='canada'>Canada</option>
</select>
</form>
</body>
</html>";
// Create a PDF renderer with form creation enabled
IronPdf.ChromePdfRenderer Renderer = new IronPdf.ChromePdfRenderer();
Renderer.RenderingOptions.CreatePdfFormsFromHtml = true;
Renderer.RenderingOptions.CssMediaType = PdfCssMediaType.Print;
Renderer.RenderingOptions.MarginTop = 20;
Renderer.RenderingOptions.MarginBottom = 20;
// Render the HTML as a PDF and save it
var pdfDocument = Renderer.RenderHtmlAsPdf(FormHtml);
pdfDocument.SaveAs("BasicForm.pdf");
// Step 2. Reading and Writing PDF form values.
var FormDocument = PdfDocument.FromFile("BasicForm.pdf");
// Get form field collection
var form = FormDocument.Form;
// Set and Read the value of the "firstname" field
var FirstNameField = form.FindFormField("firstname");
FirstNameField.Value = "Minnie";
Console.WriteLine("FirstNameField value: {0}", FirstNameField.Value);
// Set and Read the value of the "lastname" field
var LastNameField = form.FindFormField("lastname");
LastNameField.Value = "Mouse";
Console.WriteLine("LastNameField value: {0}", LastNameField.Value);
// Set email field
var EmailField = form.FindFormField("email");
EmailField.Value = "minnie.mouse@example.com";
// Set checkbox
var NewsletterField = form.FindFormField("newsletter");
NewsletterField.Value = "yes";
// Set dropdown selection
var CountryField = form.FindFormField("country");
CountryField.Value = "usa";
// Save the form with filled values
FormDocument.SaveAs("FilledForm.pdf");
// Step 3. Flattening the form (making it non-editable)
FormDocument.Form.Flatten();
FormDocument.SaveAs("FlattenedForm.pdf");// PM> Install-Package IronPdf
using IronPdf;
using IronPdf.Rendering;
// Step 1. Creating a PDF with editable forms from HTML using form and input tags
var FormHtml = @"
<html>
<head>
<style>
body { font-family: Arial, sans-serif; margin: 40px; }
h2 { color: #333; }
form { background: #f4f4f4; padding: 20px; border-radius: 8px; }
input[type='text'] {
width: 100%;
padding: 8px;
margin: 10px 0;
border: 1px solid #ddd;
border-radius: 4px;
}
input[type='checkbox'] { margin-right: 10px; }
select { width: 100%; padding: 8px; margin: 10px 0; }
</style>
</head>
<body>
<h2>Editable PDF Form</h2>
<form>
First name:<br> <input type='text' name='firstname' value=''> <br>
Last name:<br> <input type='text' name='lastname' value=''>
<br><br>
Email:<br> <input type='text' name='email' value=''>
<br><br>
Subscribe to newsletter: <input type='checkbox' name='newsletter' value='yes'>
<br><br>
Country:
<select name='country'>
<option value='usa'>United States</option>
<option value='uk'>United Kingdom</option>
<option value='canada'>Canada</option>
</select>
</form>
</body>
</html>";
// Create a PDF renderer with form creation enabled
IronPdf.ChromePdfRenderer Renderer = new IronPdf.ChromePdfRenderer();
Renderer.RenderingOptions.CreatePdfFormsFromHtml = true;
Renderer.RenderingOptions.CssMediaType = PdfCssMediaType.Print;
Renderer.RenderingOptions.MarginTop = 20;
Renderer.RenderingOptions.MarginBottom = 20;
// Render the HTML as a PDF and save it
var pdfDocument = Renderer.RenderHtmlAsPdf(FormHtml);
pdfDocument.SaveAs("BasicForm.pdf");
// Step 2. Reading and Writing PDF form values.
var FormDocument = PdfDocument.FromFile("BasicForm.pdf");
// Get form field collection
var form = FormDocument.Form;
// Set and Read the value of the "firstname" field
var FirstNameField = form.FindFormField("firstname");
FirstNameField.Value = "Minnie";
Console.WriteLine("FirstNameField value: {0}", FirstNameField.Value);
// Set and Read the value of the "lastname" field
var LastNameField = form.FindFormField("lastname");
LastNameField.Value = "Mouse";
Console.WriteLine("LastNameField value: {0}", LastNameField.Value);
// Set email field
var EmailField = form.FindFormField("email");
EmailField.Value = "minnie.mouse@example.com";
// Set checkbox
var NewsletterField = form.FindFormField("newsletter");
NewsletterField.Value = "yes";
// Set dropdown selection
var CountryField = form.FindFormField("country");
CountryField.Value = "usa";
// Save the form with filled values
FormDocument.SaveAs("FilledForm.pdf");
// Step 3. Flattening the form (making it non-editable)
FormDocument.Form.Flatten();
FormDocument.SaveAs("FlattenedForm.pdf");首先,您需要创建一个包含 HTML 格式标签的表单。 该库可以处理保存为 PDF 时的复杂情况。 表单值的读取和写入是通过FindFormField函数完成的。 您的应用程序可以立即使用此功能以编程方式填写表单。
有关高级表单处理(包括数字签名)的信息,请参阅"创建 PDF 表单"教程。
如何对 PDF 文件进行数字签名
远程办公需要高效的文档处理能力。 填写和签署表格、发送文件、处理文件是日常业务活动。 使用 PDF 文档、文件夹和表格进行签名可以取代纸质文档。 数字签名使公司能够在线签署协议和共享 PDF 表格。
使用 XFINIUM.PDF
签名域用于在 PDF 文件中应用数字签名( PdfSignatureField类)。 虽然签名栏只出现在一页上,但数字签名会对整个文档进行签名。
签名过程使用PdfDigitalSignature对象来设置签名属性。 签名是在根据 PDF 文件的二进制布局保存文档时生成的。
PdfDigitalSignature为所有 XFINIUM 签名提供基础:
PdfCmsDigitalSignature– CMS 标准签名(继承自PdfDigitalSignature)PdfPadesDigitalSignature– PADES 标准签名(继承自PdfCmsDigitalSignature)PdfInteractiveCmsDigitalSignature– 使用硬件智能卡的CMS 签名PdfInteractivePadesDigitalSignature– 支持硬件智能卡的 PADESPdfDocumentTimeStamp– 文档级时间戳(继承自PdfDigitalSignature)
使用 IronPDF.
开发人员经常询问如何使用 IronPDF 和 C# 以编程方式向 PDF 添加签名。 这可能意味着:
- 从文件中添加图形签名图像 -采用加密签名以防止篡改
- 添加带有加密签名的手写签名图标
第一种方法是将签名 PNG 图片添加到现有的 PDF 页面上。 可用于签名或公司印章:
// Open an existing PDF document or create a new one
var Pdf = PdfDocument.FromFile(@"C:\Path\To\ASPX to PDF.pdf");
// Define an HTML stamp with a signature image
var SignatureStamp = new HtmlStamp()
{
Html = "<img src='signature.png' />",
Width = 150,
Height = 50,
Bottom = 300,
Left = 85,
ZIndex = HtmlStamp.StampLayer.OnTopOfExistingPDFContent
};
// Advanced stamp with styling
var StyledSignatureStamp = new HtmlStamp()
{
Html = @"<div style='border: 2px solid #000; padding: 10px; background: rgba(255,255,255,0.9);'>
<img src='signature.png' style='width: 120px;' />
<p style='margin: 5px 0 0 0; font-size: 10px;'>Digitally Signed</p>
<p style='margin: 0; font-size: 8px;'>{date}</p>
</div>",
Width = 150,
Height = 100,
Bottom = 50,
Right = 50,
ZIndex = HtmlStamp.StampLayer.OnTopOfExistingPDFContent
};
// Stamp the signature on the first page of the PDF
Pdf.StampHTML(SignatureStamp, 1);
// Or apply to all pages
Pdf.StampHTML(StyledSignatureStamp);
// Save the stamped PDF
Pdf.SaveAs(@"C:\Path\To\Stamped_PDF.pdf");// Open an existing PDF document or create a new one
var Pdf = PdfDocument.FromFile(@"C:\Path\To\ASPX to PDF.pdf");
// Define an HTML stamp with a signature image
var SignatureStamp = new HtmlStamp()
{
Html = "<img src='signature.png' />",
Width = 150,
Height = 50,
Bottom = 300,
Left = 85,
ZIndex = HtmlStamp.StampLayer.OnTopOfExistingPDFContent
};
// Advanced stamp with styling
var StyledSignatureStamp = new HtmlStamp()
{
Html = @"<div style='border: 2px solid #000; padding: 10px; background: rgba(255,255,255,0.9);'>
<img src='signature.png' style='width: 120px;' />
<p style='margin: 5px 0 0 0; font-size: 10px;'>Digitally Signed</p>
<p style='margin: 0; font-size: 8px;'>{date}</p>
</div>",
Width = 150,
Height = 100,
Bottom = 50,
Right = 50,
ZIndex = HtmlStamp.StampLayer.OnTopOfExistingPDFContent
};
// Stamp the signature on the first page of the PDF
Pdf.StampHTML(SignatureStamp, 1);
// Or apply to all pages
Pdf.StampHTML(StyledSignatureStamp);
// Save the stamped PDF
Pdf.SaveAs(@"C:\Path\To\Stamped_PDF.pdf");使用一行代码,通过 .pfx 和 .p12 X509Certificate2 数字证书对PDF 文件进行加密签名:
// 123456 below represents the signature password
new IronPdf.PdfSignature("CertificateFile.p12", "123456").SignPdfFile("ASPX to PDF.pdf");
// Or with more control
var signature = new IronPdf.PdfSignature("CertificateFile.p12", "123456")
{
SigningContact = "john@example.com",
SigningLocation = "New York, USA",
SigningReason = "Contract Agreement"
};
// Load the PDF
var pdf = PdfDocument.FromFile("contract.pdf");
// Sign and save
pdf.SignPdfWithDigitalSignature(signature);
pdf.SaveAs("signed-contract.pdf");// 123456 below represents the signature password
new IronPdf.PdfSignature("CertificateFile.p12", "123456").SignPdfFile("ASPX to PDF.pdf");
// Or with more control
var signature = new IronPdf.PdfSignature("CertificateFile.p12", "123456")
{
SigningContact = "john@example.com",
SigningLocation = "New York, USA",
SigningReason = "Contract Agreement"
};
// Load the PDF
var pdf = PdfDocument.FromFile("contract.pdf");
// Sign and save
pdf.SignPdfWithDigitalSignature(signature);
pdf.SaveAs("signed-contract.pdf");这个高级示例将 .pfx / .p12 X509Certificate2 数字 ID 签名与手写签名相结合:
// Create a digital signature using a certificate file
var Signature = new IronPdf.PdfSignature("Iron.pfx", "123456");
// Render a PDF document to be signed
var Renderer = new ChromePdfRenderer();
Renderer.RenderingOptions.MarginBottom = 0;
Renderer.RenderingOptions.MarginTop = 0;
Renderer.RenderingOptions.EnableJavaScript = true;
Renderer.RenderingOptions.CssMediaType = IronPdf.Rendering.PdfCssMediaType.Print;
// Create PDF with security features
string html = @"<h1>Contract Agreement</h1>
<p>This document is digitally signed and encrypted.</p>
<p>Agreement Date: " + DateTime.Now.ToString("yyyy-MM-dd") + @"</p>";
PdfDocument doc = Renderer.RenderHtmlAsPdf(html);
// Configure optional signing options and a handwritten signature graphic
Signature.SigningContact = "support@ironsoftware.com";
Signature.SigningLocation = "Chicago, USA";
Signature.SigningReason = "To show how to sign a PDF";
// Load a handwritten signature image
Signature.LoadSignatureImageFromFile("handwriting.png");
// Advanced security: Set permissions
doc.SecuritySettings.AllowUserPrinting = IronPdf.Security.PdfPrintSecurity.NoPrint;
doc.SecuritySettings.AllowUserEdits = IronPdf.Security.PdfEditSecurity.NoEdit;
doc.SecuritySettings.AllowUserCopyPasteContent = false;
// Sign the PDF document with the digital signature
doc.SignPdfWithDigitalSignature(Signature);
// Add password protection
doc.Password = "userpassword";
doc.OwnerPassword = "ownerpassword";
// Save the signed PDF document
doc.SaveAs("Signed_ASPX_to_PDF.pdf");// Create a digital signature using a certificate file
var Signature = new IronPdf.PdfSignature("Iron.pfx", "123456");
// Render a PDF document to be signed
var Renderer = new ChromePdfRenderer();
Renderer.RenderingOptions.MarginBottom = 0;
Renderer.RenderingOptions.MarginTop = 0;
Renderer.RenderingOptions.EnableJavaScript = true;
Renderer.RenderingOptions.CssMediaType = IronPdf.Rendering.PdfCssMediaType.Print;
// Create PDF with security features
string html = @"<h1>Contract Agreement</h1>
<p>This document is digitally signed and encrypted.</p>
<p>Agreement Date: " + DateTime.Now.ToString("yyyy-MM-dd") + @"</p>";
PdfDocument doc = Renderer.RenderHtmlAsPdf(html);
// Configure optional signing options and a handwritten signature graphic
Signature.SigningContact = "support@ironsoftware.com";
Signature.SigningLocation = "Chicago, USA";
Signature.SigningReason = "To show how to sign a PDF";
// Load a handwritten signature image
Signature.LoadSignatureImageFromFile("handwriting.png");
// Advanced security: Set permissions
doc.SecuritySettings.AllowUserPrinting = IronPdf.Security.PdfPrintSecurity.NoPrint;
doc.SecuritySettings.AllowUserEdits = IronPdf.Security.PdfEditSecurity.NoEdit;
doc.SecuritySettings.AllowUserCopyPasteContent = false;
// Sign the PDF document with the digital signature
doc.SignPdfWithDigitalSignature(Signature);
// Add password protection
doc.Password = "userpassword";
doc.OwnerPassword = "ownerpassword";
// Save the signed PDF document
doc.SaveAs("Signed_ASPX_to_PDF.pdf");要了解完整的安全实现,请查阅Ironsecuredoc 文档,了解高级文档保护功能。## 各个库如何处理现代 CSS 框架和 Bootstrap?
现代 Web 应用程序通常依赖于 Bootstrap 等 CSS 框架来实现快速 UI 开发和响应式设计。 PDF 生成工具必须准确地保留这些框架布局,以确保文档的专业质量。
IronPDF:完整的 Bootstrap 框架支持
IronPDF 的 Chromium 渲染引擎完全支持现代 CSS 框架:
- Bootstrap 5:完全支持 Flexbox 和 CSS Grid 渲染,以及所有响应式组件
- Bootstrap 4:完整的卡片系统、导航栏和实用类
- Tailwind CSS:所有实用性优先的类及其响应式变体
- Foundation 和其他框架:完全支持 CSS3,这意味着所有现代框架都能正常工作。 -高级 CSS: Flexbox、CSS Grid、自定义属性、动画和变换
实际验证:Bootstrap 首页和模板能够以浏览器精确的保真度进行转换。
代码示例: 使用 Bootstrap 卡片的事件日程
using IronPdf;
var renderer = new ChromePdfRenderer();
// Configure rendering for optimal Bootstrap output
renderer.RenderingOptions.CssMediaType = IronPdf.Rendering.PdfCssMediaType.Print;
renderer.RenderingOptions.EnableJavaScript = true;
renderer.RenderingOptions.RenderDelay = 500; // Allow JS to fully load
renderer.RenderingOptions.ViewPortWidth = 1280; // Desktop viewport
renderer.RenderingOptions.MarginTop = 10;
renderer.RenderingOptions.MarginBottom = 10;
renderer.RenderingOptions.MarginLeft = 10;
renderer.RenderingOptions.MarginRight = 10;
string bootstrapSchedule = @"
<!DOCTYPE html>
<html>
<head>
<link href='___PROTECTED_URL_135___ rel='stylesheet'>
<style>
@media print {
.pagebreak { page-break-after: always; }
}
</style>
</head>
<body>
<div class='container my-5'>
<h1 class='text-center mb-5'>Tech Conference 2025 - Schedule</h1>
<div class='row g-4'>
<div class='col-md-6'>
<div class='card border-primary'>
<div class='card-header bg-primary text-white d-flex justify-content-between align-items-center'>
<h5 class='mb-0'>Keynote Session</h5>
<span class='badge bg-light text-primary'>9:00 AM</span>
</div>
<div class='card-body'>
<h6 class='card-subtitle mb-2 text-muted'>Main Auditorium</h6>
<p class='card-text'><strong>The Future of AI in Software Development</strong></p>
<p class='card-text'>Join us for an exploration of how artificial intelligence is transforming the software development environment.</p>
<div class='d-flex align-items-center'>
<img src='___PROTECTED_URL_136___ class='rounded-circle me-2' alt='Speaker'>
<div>
<div class='fw-bold'>Dr. Sarah Chen</div>
<small class='text-muted'>AI Research Lead</small>
</div>
</div>
</div>
</div>
</div>
<div class='col-md-6'>
<div class='card border-success'>
<div class='card-header bg-success text-white d-flex justify-content-between align-items-center'>
<h5 class='mb-0'>Workshop</h5>
<span class='badge bg-light text-success'>10:30 AM</span>
</div>
<div class='card-body'>
<h6 class='card-subtitle mb-2 text-muted'>Workshop Room A</h6>
<p class='card-text'><strong>Hands-On: Cloud-Native Architecture</strong></p>
<p class='card-text'>Learn practical techniques for building flexible, cloud-native applications with modern frameworks.</p>
<div class='d-flex align-items-center'>
<img src='___PROTECTED_URL_137___ class='rounded-circle me-2' alt='Speaker'>
<div>
<div class='fw-bold'>Michael Rodriguez</div>
<small class='text-muted'>Cloud Architect</small>
</div>
</div>
</div>
</div>
</div>
<div class='col-md-6'>
<div class='card border-warning'>
<div class='card-header bg-warning text-dark d-flex justify-content-between align-items-center'>
<h5 class='mb-0'>Panel Discussion</h5>
<span class='badge bg-dark'>2:00 PM</span>
</div>
<div class='card-body'>
<h6 class='card-subtitle mb-2 text-muted'>Main Auditorium</h6>
<p class='card-text'><strong>Security in Modern Web Applications</strong></p>
<p class='card-text'>Industry experts discuss current security challenges and best practices for protecting user data.</p>
<small class='text-muted'>Featuring 4 industry experts</small>
</div>
</div>
</div>
<div class='col-md-6'>
<div class='card border-info'>
<div class='card-header bg-info text-white d-flex justify-content-between align-items-center'>
<h5 class='mb-0'>Technical Talk</h5>
<span class='badge bg-light text-info'>3:30 PM</span>
</div>
<div class='card-body'>
<h6 class='card-subtitle mb-2 text-muted'>Room B</h6>
<p class='card-text'><strong>Performance Optimization Strategies</strong></p>
<p class='card-text'>Deep dive into advanced techniques for improve application performance and reducing latency.</p>
<div class='d-flex align-items-center'>
<img src='___PROTECTED_URL_138___ class='rounded-circle me-2' alt='Speaker'>
<div>
<div class='fw-bold'>Alex Kim</div>
<small class='text-muted'>Performance Engineer</small>
</div>
</div>
</div>
</div>
</div>
</div>
<div class='pagebreak'></div>
<h2 class='mt-5'>Additional Sessions</h2>
<div class='table-responsive'>
<table class='table table-striped'>
<thead>
<tr>
<th>Time</th>
<th>Session</th>
<th>Speaker</th>
<th>Location</th>
</tr>
</thead>
<tbody>
<tr>
<td>11:45 AM</td>
<td>Lightning Talks</td>
<td>Various</td>
<td>Room C</td>
</tr>
<tr>
<td>1:00 PM</td>
<td>Networking Lunch</td>
<td>-</td>
<td>Cafeteria</td>
</tr>
</tbody>
</table>
</div>
</div>
</body>
</html>";
// Generate the PDF
var pdf = renderer.RenderHtmlAsPdf(bootstrapSchedule);
// Add metadata
pdf.MetaData.Author = "Tech Conference Team";
pdf.MetaData.Title = "Conference Schedule 2025";
pdf.MetaData.Subject = "Event Schedule";
// Save the PDF
pdf.SaveAs("conference-schedule.pdf");
// Example: Generate responsive invoice with Bootstrap
string bootstrapInvoice = @"
<!DOCTYPE html>
<html>
<head>
<link href='___PROTECTED_URL_139___ rel='stylesheet'>
<link href='___PROTECTED_URL_140___ rel='stylesheet'>
</head>
<body>
<div class='container mt-5'>
<div class='row'>
<div class='col-12'>
<div class='card'>
<div class='card-body'>
<div class='row mb-4'>
<div class='col-sm-6'>
<h2 class='text-primary'><i class='fas fa-file-invoice'></i> INVOICE</h2>
<p class='mb-1'><strong>Invoice #:</strong> INV-2025-001</p>
<p class='mb-1'><strong>Date:</strong> " + DateTime.Now.ToString("MMMM dd, yyyy") + @"</p>
</div>
<div class='col-sm-6 text-sm-end'>
<h4>Your Company Name</h4>
<p class='mb-1'>123 Business St</p>
<p class='mb-1'>City, State 12345</p>
<p>contact@company.com</p>
</div>
</div>
<hr>
<div class='row mb-4'>
<div class='col-sm-6'>
<h5>Bill To:</h5>
<p class='mb-1'><strong>Client Company</strong></p>
<p class='mb-1'>456 Client Ave</p>
<p>City, State 67890</p>
</div>
</div>
<div class='table-responsive'>
<table class='table table-bordered'>
<thead class='table-primary'>
<tr>
<th>Description</th>
<th class='text-center'>Quantity</th>
<th class='text-end'>Price</th>
<th class='text-end'>Total</th>
</tr>
</thead>
<tbody>
<tr>
<td>Web Development Services</td>
<td class='text-center'>40</td>
<td class='text-end'>$150.00</td>
<td class='text-end'>$6,000.00</td>
</tr>
<tr>
<td>UI/UX Design</td>
<td class='text-center'>20</td>
<td class='text-end'>$125.00</td>
<td class='text-end'>$2,500.00</td>
</tr>
</tbody>
<tfoot>
<tr>
<td colspan='3' class='text-end'><strong>Subtotal:</strong></td>
<td class='text-end'><strong>$8,500.00</strong></td>
</tr>
<tr>
<td colspan='3' class='text-end'>Tax (10%):</td>
<td class='text-end'>$850.00</td>
</tr>
<tr class='table-primary'>
<td colspan='3' class='text-end'><strong>Total Due:</strong></td>
<td class='text-end'><strong>$9,350.00</strong></td>
</tr>
</tfoot>
</table>
</div>
<div class='alert alert-info mt-4'>
<i class='fas fa-info-circle'></i> Payment is due within 30 days. Thank you for your business!
</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>";
var invoicePdf = renderer.RenderHtmlAsPdf(bootstrapInvoice);
invoicePdf.SaveAs("bootstrap-invoice.pdf");using IronPdf;
var renderer = new ChromePdfRenderer();
// Configure rendering for optimal Bootstrap output
renderer.RenderingOptions.CssMediaType = IronPdf.Rendering.PdfCssMediaType.Print;
renderer.RenderingOptions.EnableJavaScript = true;
renderer.RenderingOptions.RenderDelay = 500; // Allow JS to fully load
renderer.RenderingOptions.ViewPortWidth = 1280; // Desktop viewport
renderer.RenderingOptions.MarginTop = 10;
renderer.RenderingOptions.MarginBottom = 10;
renderer.RenderingOptions.MarginLeft = 10;
renderer.RenderingOptions.MarginRight = 10;
string bootstrapSchedule = @"
<!DOCTYPE html>
<html>
<head>
<link href='___PROTECTED_URL_135___ rel='stylesheet'>
<style>
@media print {
.pagebreak { page-break-after: always; }
}
</style>
</head>
<body>
<div class='container my-5'>
<h1 class='text-center mb-5'>Tech Conference 2025 - Schedule</h1>
<div class='row g-4'>
<div class='col-md-6'>
<div class='card border-primary'>
<div class='card-header bg-primary text-white d-flex justify-content-between align-items-center'>
<h5 class='mb-0'>Keynote Session</h5>
<span class='badge bg-light text-primary'>9:00 AM</span>
</div>
<div class='card-body'>
<h6 class='card-subtitle mb-2 text-muted'>Main Auditorium</h6>
<p class='card-text'><strong>The Future of AI in Software Development</strong></p>
<p class='card-text'>Join us for an exploration of how artificial intelligence is transforming the software development environment.</p>
<div class='d-flex align-items-center'>
<img src='___PROTECTED_URL_136___ class='rounded-circle me-2' alt='Speaker'>
<div>
<div class='fw-bold'>Dr. Sarah Chen</div>
<small class='text-muted'>AI Research Lead</small>
</div>
</div>
</div>
</div>
</div>
<div class='col-md-6'>
<div class='card border-success'>
<div class='card-header bg-success text-white d-flex justify-content-between align-items-center'>
<h5 class='mb-0'>Workshop</h5>
<span class='badge bg-light text-success'>10:30 AM</span>
</div>
<div class='card-body'>
<h6 class='card-subtitle mb-2 text-muted'>Workshop Room A</h6>
<p class='card-text'><strong>Hands-On: Cloud-Native Architecture</strong></p>
<p class='card-text'>Learn practical techniques for building flexible, cloud-native applications with modern frameworks.</p>
<div class='d-flex align-items-center'>
<img src='___PROTECTED_URL_137___ class='rounded-circle me-2' alt='Speaker'>
<div>
<div class='fw-bold'>Michael Rodriguez</div>
<small class='text-muted'>Cloud Architect</small>
</div>
</div>
</div>
</div>
</div>
<div class='col-md-6'>
<div class='card border-warning'>
<div class='card-header bg-warning text-dark d-flex justify-content-between align-items-center'>
<h5 class='mb-0'>Panel Discussion</h5>
<span class='badge bg-dark'>2:00 PM</span>
</div>
<div class='card-body'>
<h6 class='card-subtitle mb-2 text-muted'>Main Auditorium</h6>
<p class='card-text'><strong>Security in Modern Web Applications</strong></p>
<p class='card-text'>Industry experts discuss current security challenges and best practices for protecting user data.</p>
<small class='text-muted'>Featuring 4 industry experts</small>
</div>
</div>
</div>
<div class='col-md-6'>
<div class='card border-info'>
<div class='card-header bg-info text-white d-flex justify-content-between align-items-center'>
<h5 class='mb-0'>Technical Talk</h5>
<span class='badge bg-light text-info'>3:30 PM</span>
</div>
<div class='card-body'>
<h6 class='card-subtitle mb-2 text-muted'>Room B</h6>
<p class='card-text'><strong>Performance Optimization Strategies</strong></p>
<p class='card-text'>Deep dive into advanced techniques for improve application performance and reducing latency.</p>
<div class='d-flex align-items-center'>
<img src='___PROTECTED_URL_138___ class='rounded-circle me-2' alt='Speaker'>
<div>
<div class='fw-bold'>Alex Kim</div>
<small class='text-muted'>Performance Engineer</small>
</div>
</div>
</div>
</div>
</div>
</div>
<div class='pagebreak'></div>
<h2 class='mt-5'>Additional Sessions</h2>
<div class='table-responsive'>
<table class='table table-striped'>
<thead>
<tr>
<th>Time</th>
<th>Session</th>
<th>Speaker</th>
<th>Location</th>
</tr>
</thead>
<tbody>
<tr>
<td>11:45 AM</td>
<td>Lightning Talks</td>
<td>Various</td>
<td>Room C</td>
</tr>
<tr>
<td>1:00 PM</td>
<td>Networking Lunch</td>
<td>-</td>
<td>Cafeteria</td>
</tr>
</tbody>
</table>
</div>
</div>
</body>
</html>";
// Generate the PDF
var pdf = renderer.RenderHtmlAsPdf(bootstrapSchedule);
// Add metadata
pdf.MetaData.Author = "Tech Conference Team";
pdf.MetaData.Title = "Conference Schedule 2025";
pdf.MetaData.Subject = "Event Schedule";
// Save the PDF
pdf.SaveAs("conference-schedule.pdf");
// Example: Generate responsive invoice with Bootstrap
string bootstrapInvoice = @"
<!DOCTYPE html>
<html>
<head>
<link href='___PROTECTED_URL_139___ rel='stylesheet'>
<link href='___PROTECTED_URL_140___ rel='stylesheet'>
</head>
<body>
<div class='container mt-5'>
<div class='row'>
<div class='col-12'>
<div class='card'>
<div class='card-body'>
<div class='row mb-4'>
<div class='col-sm-6'>
<h2 class='text-primary'><i class='fas fa-file-invoice'></i> INVOICE</h2>
<p class='mb-1'><strong>Invoice #:</strong> INV-2025-001</p>
<p class='mb-1'><strong>Date:</strong> " + DateTime.Now.ToString("MMMM dd, yyyy") + @"</p>
</div>
<div class='col-sm-6 text-sm-end'>
<h4>Your Company Name</h4>
<p class='mb-1'>123 Business St</p>
<p class='mb-1'>City, State 12345</p>
<p>contact@company.com</p>
</div>
</div>
<hr>
<div class='row mb-4'>
<div class='col-sm-6'>
<h5>Bill To:</h5>
<p class='mb-1'><strong>Client Company</strong></p>
<p class='mb-1'>456 Client Ave</p>
<p>City, State 67890</p>
</div>
</div>
<div class='table-responsive'>
<table class='table table-bordered'>
<thead class='table-primary'>
<tr>
<th>Description</th>
<th class='text-center'>Quantity</th>
<th class='text-end'>Price</th>
<th class='text-end'>Total</th>
</tr>
</thead>
<tbody>
<tr>
<td>Web Development Services</td>
<td class='text-center'>40</td>
<td class='text-end'>$150.00</td>
<td class='text-end'>$6,000.00</td>
</tr>
<tr>
<td>UI/UX Design</td>
<td class='text-center'>20</td>
<td class='text-end'>$125.00</td>
<td class='text-end'>$2,500.00</td>
</tr>
</tbody>
<tfoot>
<tr>
<td colspan='3' class='text-end'><strong>Subtotal:</strong></td>
<td class='text-end'><strong>$8,500.00</strong></td>
</tr>
<tr>
<td colspan='3' class='text-end'>Tax (10%):</td>
<td class='text-end'>$850.00</td>
</tr>
<tr class='table-primary'>
<td colspan='3' class='text-end'><strong>Total Due:</strong></td>
<td class='text-end'><strong>$9,350.00</strong></td>
</tr>
</tfoot>
</table>
</div>
<div class='alert alert-info mt-4'>
<i class='fas fa-info-circle'></i> Payment is due within 30 days. Thank you for your business!
</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>";
var invoicePdf = renderer.RenderHtmlAsPdf(bootstrapInvoice);
invoicePdf.SaveAs("bootstrap-invoice.pdf");输出:一个专业的会议日程表,采用 Bootstrap 的卡片网格、flexbox 对齐方式、徽章组件和响应式布局——所有内容都准确地渲染在 PDF 中。
XFINIUM.PDF:有限的 HTML 和框架支持
XFINIUM.PDF 专注于 PDF 的生成和处理,而不是 HTML 到 PDF 的转换。 该库在 Bootstrap 和现代 CSS 框架方面存在显著限制:
-不支持原生 HTML 渲染: XFINIUM.PDF 不包含内置的 HTML 到 PDF 转换引擎。 -仅支持基本 HTML:仅限于简单的 HTML 结构,不支持高级 CSS -不支持 Bootstrap:不支持带有 flexbox 和 CSS Grid 的现代 Bootstrap 框架(4/5 版本)。 -需要采取变通方法:开发人员必须使用底层 PDF API 手动重新创建布局。 -需要外部工具:可能需要与外部 HTML 渲染引擎集成
开发影响:使用 Bootstrap 或现代 CSS 框架的应用程序无法使用 XFINIUM.PDF 直接将其 UI 转换为 PDF。 开发人员必须:
- 使用 XFINIUM.PDF 的低级绘图 API 重建布局(显著开发时间)
- 集成外部 HTML 渲染工具(增加复杂性和依赖关系)
- 维护与 Web UI 平行的单独 PDF 布局代码(维护开销)
对于需要使用现代框架将 HTML 转换为 PDF 的项目,XFINIUM.PDF 的局限性需要进行大量的额外开发。
如需了解 Bootstrap 和现代 CSS 框架的完整支持,请参阅 Bootstrap 和 Flexbox CSS 指南。
定价和许可方案有哪些?
XFINIUM.PDF 定价和许可
每个软件包都有两个版本:生成器版本用于 PDF 生成/编辑,查看器版本包含所有生成器功能以及 PDF 渲染和查看功能。
每个开发者都需要许可证。
- 可免版税分发至无限数量的桌面/服务器。
- 协助订阅包含一年的更新/支持服务。
价格范围为每年 290.00 美元至 872.00 美元。
IronPDF 定价和许可
IronPDF 可供开发使用,并可随时授权用于商业用途。授权选项包括单项目授权、单个开发者授权、代理机构授权、跨国组织授权以及 SaaS/OEM 再分发授权。 所有许可证均包含 30 天退款保证、一年支持/升级、开发/测试/生产有效期以及永久许可证(一次性购买)。 Lite 套餐起价为$799 ,无任何经常性费用。
我应该选择哪个PDF库?
IronPDF库简化了PDF的创建过程,无需使用专有API。"HTML-To-PDF"功能可以将HTML、JS、CSS、JPG、PNG、GIF和SVG等开放标准文档转换为像素级完美的PDF文件。 它建立在现有开发人员技能的基础上。 您可以下载文档、通过电子邮件发送或保存到云端,从而创建账单、报价单、报告、合同和其他文书工作。 它适用于 ASP.NET、ASP.NET Core、webforms、MVC、.NET Framework 和 .NET Core Web API。
XFINIUM.PDF 为初级和高级 PDF 开发人员提供功能。 无论您需要创建报告、填写 PDF 表格、构建作品集、编辑信息,还是将 PDF 转换为多页 TIFF,它都能提供必要的工具。 基本对象模型遵循PDF规范。 代码无需修改即可在所有平台上编译。
XFINIUM.PDF 许可证起价为 290 美元(生成器)和 387 美元(查看器)版本。 IronPDF 的起价为$799 。 IronPDF 提供单用户和多用户许可证,而 XFINIUM.PDF 则需要为每个开发人员购买许可证。 IronPDF 专业版许可证(799 美元)支持无限用户。
IronPDF 处理 PDF 文件所需的代码行数比 XFINIUM.PDF 少,从而减轻了程序员的工作量。
Iron Software 提供全套软件,只需点击两下即可使用。 目前,只需支付两个库的价格,即可获得全部五个库以及持续的支持。
常见问题解答
IronPDF进行HTML到PDF转换的关键功能是什么?
IronPDF利用.NET Chromium引擎将HTML转换为PDF。它支持HTML5、CSS、JavaScript和图像集成,使其成为从网页内容创建PDF的综合解决方案。
XFINIUM.PDF与其他.NET PDF库相比如何?
XFINIUM.PDF是一个提供两种版本的跨平台库:生成器和查看器。它在PDF创建、编辑、渲染方面表现出色,并包括安全性、数字签名和条形码支持等功能。
IronPDF可以用于像Azure和AWS这样的云平台吗?
可以,IronPDF兼容各种平台,包括Azure和AWS,允许在云环境中灵活部署PDF解决方案。
在.NET项目中,有哪些IronPDF安装选项?
IronPDF可以通过Visual Studio的NuGet包管理器、开发者命令提示符安装,或直接下载NuGet包或库DLL。
IronPDF的PDF编辑功能有哪些?
IronPDF允许广泛的PDF编辑,包括填写表单字段、合并文档以及提取文本和图像。它还支持添加页眉、页脚和注释。
IronPDF和XFINIUM.PDF的许可选项有何不同?
XFINIUM.PDF提供每位开发人员$290起的许可证,支持免费发行。IronPDF提供更宽泛的许可选项,包括针对无限用户的专业许可证。
XFINIUM.PDF提供什么安全功能?
XFINIUM.PDF支持如用户和拥有者密码、文档访问权限、RC4和AES加密、内容隐藏等安全功能,以确保文档安全。
开发人员为何可能选择IronPDF用于他们的项目?
开发人员可能会选择IronPDF因为其简化的PDF操作,仅需较少的代码行,并且在单用户和多用户许可证方面灵活多变。
IronPDF如何处理PDF中的表单填写?
IronPDF提供工具用于填写PDF内的表单字段,允许动态创建文档和用户互动。
这些PDF库有哪些数字签名功能?
IronPDF和XFINIUM.PDF均支持数字签名,使得文档真实性和完整性得到安全验证。






