PDF控件Spire.PDF for .NET【安全】演示:使用文本或/和图像对 PDF 进行数字签名

这篇具有很好参考价值的文章主要介绍了PDF控件Spire.PDF for .NET【安全】演示:使用文本或/和图像对 PDF 进行数字签名。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

数字签名确保签名的文档不能被除其作者之外的任何人更改。添加签名是确保文档内容真实性的最常见方法。PDF 文档中的可视数字签名可以显示文本或图像(例如手写签名)。本文从以下三个方面介绍如何使用Spire.PDF for .NET对PDF 进行数字签名。

Spire.PDF for .NET 是一款独立 PDF 控件,用于 .NET 程序中创建、编辑和操作 PDF 文档。使用 Spire.PDF 类库,开发人员可以新建一个 PDF 文档或者对现有的 PDF 文档进行处理,且无需安装 Adobe Acrobat。

E-iceblue 功能类库Spire 系列文档处理组件均由中国本土团队研发,不依赖第三方软件,不受其他国家的技术或法律法规限制,同时适配国产操作系统如中科方德、中标麒麟等,兼容国产文档处理软件 WPS(如 .wps/.et/.dps 等格式

Spire.PDF for.net下载   Spire.PDF for java下载

安装适用于 .NET 的 Spire.PDF

首先,您需要将 Spire.PDF for .NET 包中包含的 DLL 文件添加为 .NET 项目中的引用。DLL 文件可以从此链接下载或通过NuGet安装。

PM> Install-Package Spire.PDF

使用文本对 PDF 进行数字签名

以下是将纯文本签名添加到 PDF 文档的步骤。

  • 创建一个PdfDocument对象,并使用PdfDocument.LoadFromFile()方法加载示例 PDF 文件。
  • 初始化PdfCertificate对象时加载 .pfx 证书文件。
  • 创建一个PdfSignature对象,指定其在文档中的位置和大小。
  • 将签名图形模式设置为SignDetail,这将以纯文本形式显示签名详细信息。
  • 通过PdfSignature对象下的属性设置签名详细信息,包括姓名、联系信息、原因、日期等。
  • 将认证文档的权限设置为ForbidChangesAllowFormFill
  • 使用PdfDocument.SaveToFile()方法将文档保存到另一个文件。

【C#】

using Spire.Pdf;
using Spire.Pdf.Security;
using System;
using System.Drawing;
using Spire.Pdf.Graphics;

namespace AddTextSignature
{
class Program
{
static void Main(string[] args)
{
//Create a PdfDocument object
PdfDocument doc = new PdfDocument();

//Load a sample PDF file
doc.LoadFromFile("C:\\Users\\Administrator\\Desktop\\sample.pdf");

//Load the certificate
PdfCertificate cert = new PdfCertificate("C:\\Users\\Administrator\\Desktop\\MyCertificate.pfx", "e-iceblue");

//Create a PdfSignature object and specify its position and size
PdfSignature signature = new PdfSignature(doc, doc.Pages[doc.Pages.Count-1], cert, "MySignature");
RectangleF rectangleF = new RectangleF(doc.Pages[0].ActualSize.Width - 340, 150, 290, 100);
signature.Bounds = rectangleF;
signature.Certificated = true;

//Set the graphics mode to sign detail
signature.GraphicsMode = GraphicMode.SignDetail;

//Set the signature content
signature.NameLabel = "Signer:";
signature.Name = "Gary";
signature.ContactInfoLabel = "Phone:";
signature.ContactInfo = "0123456";
signature.DateLabel = "Date:";
signature.Date = DateTime.Now;
signature.LocationInfoLabel = "Location:";
signature.LocationInfo = "USA";
signature.ReasonLabel = "Reason:";
signature.Reason = "I am the author";
signature.DistinguishedNameLabel = "DN:";
signature.DistinguishedName = signature.Certificate.IssuerName.Name;

//Set the signature font
signature.SignDetailsFont = new PdfTrueTypeFont(new Font("Arial Unicode MS",12f,FontStyle.Regular));

//Set the document permission to forbid changes but allow form fill
signature.DocumentPermissions = PdfCertificationFlags.ForbidChanges | PdfCertificationFlags.AllowFormFill;

//Save to file
doc.SaveToFile("TextSignature.pdf");
doc.Close();
}
}
}

【VB.NET】

Imports Spire.Pdf
Imports Spire.Pdf.Security
Imports System
Imports System.Drawing
Imports Spire.Pdf.Graphics

Namespace AddTextSignature
Class Program
Shared Sub Main(ByVal args() As String)
'Create a PdfDocument object
Dim doc As PdfDocument = New PdfDocument()

'Load a sample PDF file
doc.LoadFromFile("C:\\Users\\Administrator\\Desktop\\sample.pdf")

'Load the certificate
Dim cert As PdfCertificate = New PdfCertificate("C:\\Users\\Administrator\\Desktop\\MyCertificate.pfx","e-iceblue")

'Create a PdfSignature object and specify its position and size
Dim signature As PdfSignature = New PdfSignature(doc,doc.Pages(doc.Pages.Count-1),cert,"MySignature")
Dim rectangleF As RectangleF = New RectangleF(doc.Pages(0).ActualSize.Width - 340,150,290,100)
signature.Bounds = rectangleF
signature.Certificated = True

'Set the graphics mode to sign detail
signature.GraphicsMode = GraphicMode.SignDetail

'Set the signature content
signature.NameLabel = "Signer:"
signature.Name = "Gary"
signature.ContactInfoLabel = "Phone:"
signature.ContactInfo = "0123456"
signature.DateLabel = "Date:"
signature.Date = DateTime.Now
signature.LocationInfoLabel = "Location:"
signature.LocationInfo = "USA"
signature.ReasonLabel = "Reason:"
signature.Reason = "I am the author"
signature.DistinguishedNameLabel = "DN:"
signature.DistinguishedName = signature.Certificate.IssuerName.Name

'Set the signature font
signature.SignDetailsFont = New PdfTrueTypeFont(New Font("Arial Unicode MS",12f,FontStyle.Regular))

'Set the document permission to forbid changes but allow form fill
signature.DocumentPermissions = PdfCertificationFlags.ForbidChanges | PdfCertificationFlags.AllowFormFill

'Save to file
doc.SaveToFile("TextSignature.pdf")
doc.Close()
End Sub
End Class
End Namespace

PDF控件Spire.PDF for .NET【安全】演示:使用文本或/和图像对 PDF 进行数字签名,Spire.PDF for .Net 教程,pdf,.net,安全,spire.pdf,数字签名

使用图像对 PDF 进行数字签名

以下是将图像签名添加到 PDF 文档的步骤。

  • 创建一个PdfDocument对象,并使用PdfDocument.LoadFromFile()方法加载示例 PDF 文件。
  • 初始化PdfCertificate对象时加载 .pfx 证书文件。
  • 创建一个PdfSignature对象,指定其在文档中的位置和大小。
  • 将签名图形模式设置为SignImageOnly,这将仅显示签名图像。
  • 通过PdfSignature.SignImageSource属性设置签名图像。
  • 将认证文档的权限设置为ForbidChangesAllowFormFill
  • 使用PdfDocument.SaveToFile()方法将文档保存到另一个文件。

【C#】

using Spire.Pdf;
using Spire.Pdf.Graphics;
using Spire.Pdf.Security;
using System.Drawing;

namespace AddImageSignature
{
class Program
{
static void Main(string[] args)
{
//Create a PdfDocument object
PdfDocument doc = new PdfDocument();

//Load a sample PDF file
doc.LoadFromFile("C:\\Users\\Administrator\\Desktop\\sample.pdf");

//Load the certificate
PdfCertificate cert = new PdfCertificate("C:\\Users\\Administrator\\Desktop\\MyCertificate.pfx", "e-iceblue");

//Create a PdfSignature object and specify its position and size
PdfSignature signature = new PdfSignature(doc, doc.Pages[doc.Pages.Count - 1], cert, "MySignature");
RectangleF rectangleF = new RectangleF(doc.Pages[0].ActualSize.Width - 200, 150, 130, 130);
signature.Bounds = rectangleF;
signature.Certificated = true;

//Set the graphics mode to image only
signature.GraphicsMode = GraphicMode.SignImageOnly;

//Set the sign image source
signature.SignImageSource = PdfImage.FromFile("C:\\Users\\Administrator\\Desktop\\verified.png");

//Set the signature font
signature.SignDetailsFont = new PdfTrueTypeFont(new Font("Arial Unicode MS", 12f, FontStyle.Regular));

//Set the document permission to forbid changes but allow form fill
signature.DocumentPermissions = PdfCertificationFlags.ForbidChanges | PdfCertificationFlags.AllowFormFill;

//Save to file
doc.SaveToFile("ImageSignature.pdf");
doc.Close();
}
}
}

【VB.NET】

Imports Spire.Pdf
Imports Spire.Pdf.Graphics
Imports Spire.Pdf.Security
Imports System.Drawing

Namespace AddImageSignature
Class Program
Shared Sub Main(ByVal args() As String)
'Create a PdfDocument object
Dim doc As PdfDocument = New PdfDocument()

'Load a sample PDF file
doc.LoadFromFile("C:\\Users\\Administrator\\Desktop\\sample.pdf")

'Load the certificate
Dim cert As PdfCertificate = New PdfCertificate("C:\\Users\\Administrator\\Desktop\\MyCertificate.pfx","e-iceblue")

'Create a PdfSignature object and specify its position and size
Dim signature As PdfSignature = New PdfSignature(doc,doc.Pages(doc.Pages.Count - 1),cert,"MySignature")
Dim rectangleF As RectangleF = New RectangleF(doc.Pages(0).ActualSize.Width - 200,150,130,130)
signature.Bounds = rectangleF
signature.Certificated = True

'Set the graphics mode to image only
signature.GraphicsMode = GraphicMode.SignImageOnly

'Set the sign image source
signature.SignImageSource = PdfImage.FromFile("C:\\Users\\Administrator\\Desktop\\verified.png")

'Set the signature font
signature.SignDetailsFont = New PdfTrueTypeFont(New Font("Arial Unicode MS", 12f, FontStyle.Regular))

'Set the document permission to forbid changes but allow form fill
signature.DocumentPermissions = PdfCertificationFlags.ForbidChanges | PdfCertificationFlags.AllowFormFill

'Save to file
doc.SaveToFile("ImageSignature.pdf")
doc.Close()
End Sub
End Class
End Namespace

PDF控件Spire.PDF for .NET【安全】演示:使用文本或/和图像对 PDF 进行数字签名,Spire.PDF for .Net 教程,pdf,.net,安全,spire.pdf,数字签名

使用文本和图像对 PDF 进行数字签名

以下是使用文本和图像对 PDF 文档进行数字签名的步骤。

  • 创建一个PdfDocument对象,并使用PdfDocument.LoadFromFile()方法加载示例 PDF 文件。
  • 初始化PdfCertificate对象时加载 .pfx 证书文件。
  • 创建一个PdfSignature对象,指定其在文档中的位置和大小。
  • 将签名图形模式设置为SignImageAndSignDetail,这将同时显示签名图像和详细信息。
  • 通过PdfSignature.SignImageSource属性设置签名图像,并通过 PdfSignature 对象下的其他属性设置签名详细信息,包括姓名、联系信息、原因、日期等。
  • 将认证文档的权限设置为ForbidChangesAllowFormFill
  • 使用PdfDocument.SaveToFile()方法将文档保存到另一个文件。

【C#】

using Spire.Pdf;
using Spire.Pdf.Security;
using System;
using System.Drawing;
using Spire.Pdf.Graphics;

namespace AddTextAndImageSignature
{
class Program
{
static void Main(string[] args)
{
//Create a PdfDocument object
PdfDocument doc = new PdfDocument();

//Load a sample PDF file
doc.LoadFromFile("C:\\Users\\Administrator\\Desktop\\sample.pdf");

//Load the certificate
PdfCertificate cert = new PdfCertificate("C:\\Users\\Administrator\\Desktop\\MyCertificate.pfx", "e-iceblue");

//Create a PdfSignature object and specify its position and size
PdfSignature signature = new PdfSignature(doc, doc.Pages[doc.Pages.Count - 1], cert, "MySignature");
RectangleF rectangleF = new RectangleF(doc.Pages[0].ActualSize.Width - 320, 150, 260, 110);
signature.Bounds = rectangleF;
signature.Certificated = true;

//Set the graphics mode to image and sign detail
signature.GraphicsMode = GraphicMode.SignImageAndSignDetail;

//Set the signature content
signature.NameLabel = "Signer:";
signature.Name = "Gary";
signature.ContactInfoLabel = "Phone:";
signature.ContactInfo = "0123456";
signature.DateLabel = "Date:";
signature.Date = DateTime.Now;
signature.LocationInfoLabel = "Location:";
signature.LocationInfo = "USA";
signature.ReasonLabel = "Reason:";
signature.Reason = "I am the author";
signature.DistinguishedNameLabel = "DN:";
signature.DistinguishedName = signature.Certificate.IssuerName.Name;

//Set the signature image source
signature.SignImageSource = PdfImage.FromFile("C:\\Users\\Administrator\\Desktop\\handSignature.png");

//Set the signature font
signature.SignDetailsFont = new PdfTrueTypeFont(new Font("Arial Unicode MS", 12f, FontStyle.Regular));

//Set the document permission to forbid changes but allow form fill
signature.DocumentPermissions = PdfCertificationFlags.ForbidChanges | PdfCertificationFlags.AllowFormFill;

//Save to file
doc.SaveToFile("TextAndImageSignature.pdf");
doc.Close();
}
}
}

【VB.NET】

Imports Spire.Pdf
Imports Spire.Pdf.Security
Imports System
Imports System.Drawing
Imports Spire.Pdf.Graphics

Namespace AddTextAndImageSignature
Class Program
Shared Sub Main(ByVal args() As String)
'Create a PdfDocument object
Dim doc As PdfDocument = New PdfDocument()

'Load a sample PDF file
doc.LoadFromFile("C:\\Users\\Administrator\\Desktop\\sample.pdf")

'Load the certificate
Dim cert As PdfCertificate = New PdfCertificate("C:\\Users\\Administrator\\Desktop\\MyCertificate.pfx","e-iceblue")

'Create a PdfSignature object and specify its position and size
Dim signature As PdfSignature = New PdfSignature(doc,doc.Pages(doc.Pages.Count - 1),cert,"MySignature")
Dim rectangleF As RectangleF = New RectangleF(doc.Pages(0).ActualSize.Width - 320,150,260,110)
signature.Bounds = rectangleF
signature.Certificated = True

'Set the graphics mode to image and sign detail
signature.GraphicsMode = GraphicMode.SignImageAndSignDetail

'Set the signature content
signature.NameLabel = "Signer:"
signature.Name = "Gary"
signature.ContactInfoLabel = "Phone:"
signature.ContactInfo = "0123456"
signature.DateLabel = "Date:"
signature.Date = DateTime.Now
signature.LocationInfoLabel = "Location:"
signature.LocationInfo = "USA"
signature.ReasonLabel = "Reason:"
signature.Reason = "I am the author"
signature.DistinguishedNameLabel = "DN:"
signature.DistinguishedName = signature.Certificate.IssuerName.Name

'Set the signature image source
signature.SignImageSource = PdfImage.FromFile("C:\\Users\\Administrator\\Desktop\\handSignature.png")

'Set the signature font
signature.SignDetailsFont = New PdfTrueTypeFont(New Font("Arial Unicode MS", 12f, FontStyle.Regular))

'Set the document permission to forbid changes but allow form fill
signature.DocumentPermissions = PdfCertificationFlags.ForbidChanges | PdfCertificationFlags.AllowFormFill

'Save to file
doc.SaveToFile("TextAndImageSignature.pdf")
doc.Close()
End Sub
End Class
End Namespace

PDF控件Spire.PDF for .NET【安全】演示:使用文本或/和图像对 PDF 进行数字签名,Spire.PDF for .Net 教程,pdf,.net,安全,spire.pdf,数字签名

以上便是如何使用文本或/和图像对 PDF 进行数字签名,如果您有其他问题也可以继续浏览本系列文章,获取相关教程~文章来源地址https://www.toymoban.com/news/detail-819270.html

到了这里,关于PDF控件Spire.PDF for .NET【安全】演示:使用文本或/和图像对 PDF 进行数字签名的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • PDF控件Spire.PDF for .NET【安全】演示:在 PDF 中添加或删除数字签名

    随着 PDF 文档在商业中越来越流行,确保其真实性已成为一个关键问题。使用基于证书的签名对 PDF 进行签名可以保护内容,还可以让其他人知道谁签署或批准了该文档。在本文中,您将了解如何使用不可见或可见签名对 PDF 进行数字签名,以及如何使用Spire.PDF for .NET从 PDF 中

    2024年02月03日
    浏览(40)
  • Spire.PDF for .NET【文档操作】演示:合并 PDF 文件并添加页码

    需要合并 PDF 的原因有很多。例如,合并 PDF 文件允许您打印单个文件,而不是为打印机排队多个文档,组合相关文件通过减少要搜索和组织的文件数量来简化管理和存储多个文档的过程。在本文中,您将学习如何使用Spire.PDF for .NET将多个 PDF 文档合并为一个 PDF 文档,以及如

    2024年04月09日
    浏览(67)
  • Spire.PDF for .NET【文档操作】演示:动态创建 PDF 并将其发送到客户端浏览器

    可移植文档格式 (PDF) 是 Adobe 制定的独立规范的固定版式文档。它封装了完整的描述,包括文本字体、图形和显示它所需的其他信息。 Spire.PDF for .NET 是一款独立 PDF 控件,用于 .NET 程序中创建、编辑和操作 PDF 文档。使用 Spire.PDF 类库,开发人员可以新建一个 PDF 文档或者对现

    2024年04月25日
    浏览(36)
  • PDF处理控件aspose.PDF功能演示:使用 C# .NET 复制 PDF 页面

    作为程序员,您通常必须以纯文本形式从 PDF 文件中提取内容以进行进一步处理,例如分析和信息提取。如果没有合适的工具,处理 PDF 文件并将整个 PDF 转换为 TXT 格式是一项麻烦的任务。因此,在本博客中,我们将探讨如何使用 C# 以编程方式将 PDF 文件转换为 TXT 格式。 A

    2024年01月23日
    浏览(39)
  • Spire.PDF for .NET 9.8.5 Crack

    Spire.PDF for .NET is a professional PDF API applied to creating, writing, editing, handling and reading PDF files without any external dependencies within .NET ( C#, VB.NET, ASP.NET, .NET Core, .NET 5.0, .NET 6.0, .NET 7.0, MonoAndroid and Xamarin.iOS ) application. Using this .NET PDF library, you can implement rich capabilities to create PDF files from sc

    2024年02月10日
    浏览(33)
  • PDF处理控件Aspose.PDF功能演示:使用Java将Base64字符串转换为PDF/JPG/PNG图像

    Aspose.PDF  是一款高级PDF处理API,可以在跨平台应用程序中轻松生成,修改,转换,呈现,保护和打印文档。无需使用Adobe Acrobat。此外,API提供压缩选项,表创建和处理,图形和图像功能,广泛的超链接功能,图章和水印任务,扩展的安全控件和自定义字体处理。 Aspose API支持

    2024年02月04日
    浏览(60)
  • Word控件Spire.Doc 【图像形状】教程(1) ;如何在 Word 中插入图像(C#/VB.NET)

    Spire.Doc for .NET是一款专门对 Word 文档进行操作的 .NET 类库。在于帮助开发人员无需安装 Microsoft Word情况下,轻松快捷高效地创建、编辑、转换和打印 Microsoft Word 文档。拥有近10年专业开发经验Spire系列办公文档开发工具,专注于创建、编辑、转换和打印Word/PDF/Excel等格式文件处

    2024年02月07日
    浏览(27)
  • Spire.Barcode for Java 5.1.0 + Spire.Barcode for .NET 7.2.0

    Spire.Barcode for Java is a professional barcode component specially designed for developers to generate, read and scan 1D 2D barcodes on Java applications (J2SE and J2EE). Developers and programmers can use Spire.Barcode to add Enterprise-Level barcode formats to their Java applications quickly and easily. Spire.Barcode for Java provides a very easy way to

    2024年02月16日
    浏览(33)
  • Spire.Office for.NET Crack

    Spire.Office for.NET是E-iceblue提供的企业级Office.NET API的组合。它包括Spire.Doc、Spire.XLS、Spire.Seadsheet、Spire.Presentation、Spire_PDF、Spire.DataExport、SpireOfficeViewer、Spire-PDFViewer、Spire.DocViewer、Spire.Barcode和Spire.Email.Spire.Office包含上述.NET API的最新版本。 使用Spire.Officefor.NET,开发人员可以创

    2024年02月15日
    浏览(36)
  • Spire.Office for .NET 8.4.1 FIX

    Spire.Office for .NET is a combination of Enterprise-Level Office .NET API offered by E-iceblue. It includes Spire.Doc, Spire.XLS, Spire.Spreadsheet, Spire.Presentation, Spire.PDF, Spire.DataExport, Spire.OfficeViewer, Spire.PDFViewer, Spire.DocViewer, Spire.Barcode and Spire.Email. Spire.Office contains the most up-to-date versions of the above .NET API.  

    2024年02月02日
    浏览(24)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包