IronPDF 操作指南 签名PDF文档 A Developer's Guide to Digitally Signing PDFs with C# Jacob Mellor 已更新:十一月 13, 2025 Download IronPDF NuGet 下载 DLL 下载 Windows 安装程序 Start Free Trial Copy for LLMs Copy for LLMs Copy page as Markdown for LLMs Open in ChatGPT Ask ChatGPT about this page Open in Gemini Ask Gemini about this page Open in Grok Ask Grok about this page Open in Perplexity Ask Perplexity about this page Share Share on Facebook Share on X (Twitter) Share on LinkedIn Copy URL Email article This article was translated from English: Does it need improvement? Translated View the article in English 在许多应用程序中,向 PDF 文档添加签名是一个常见的需求,但“签名”可能意味着不同的事情。 对于某些人来说,这涉及使用安全证书应用防篡改的数字签名。 对其他人来说,这可能是在文件上加盖可视的手写签名图像,或添加一个交互式表单字段供用户以电子方式签名。 本指南为 C# 开发人员提供了一个全面的操作指南,教您如何使用 IronPDF for .NET 库 完成所有这些任务。 我们将介绍从应用安全 X509Certificate2 数字签名到加盖图形签名和创建交互式签名字段的所有方面,确保您的 PDF 文档是可信、安全和专业的。 副标题:2(快速入门:利用 IronPDF 轻松数字签署 PDF) 通过简单、直接的过程,快速开始使用 IronPDF 来数字签署您的 PDF 文档。 此示例演示如何使用 .pfx 证书验证和签署 PDF 文件,确保文档的完整性和真实性。 按照这些步骤无缝集成数字签名到您的应用程序中,为您的用户提供安全可靠的 PDF 功能。 Get started making PDFs with NuGet now: Install IronPDF with NuGet Package Manager PM > Install-Package IronPdf Copy and run this code snippet. new IronPdf.Signing.PdfSignature("certificate.pfx", "password").SignPdfFile("input.pdf"); Deploy to test on your live environment Start using IronPDF in your project today with a free trial Free 30 day Trial class="hsg-featured-snippet"> 最小工作流 (5 步骤) 为 .NET 安装 IronPDF 库。 使用 X509Certificate2 对象应用数字签名。 添加视觉图像以表示数字签名。 在 PDF 文件上加盖图形或手写签名。 为电子签名添加交互式签名表单字段。 如何使用证书对 PDF 应用数字签名? 您可以使用数字证书文件(例如 .pfx 或 .p12)对 PDF 文档应用数字签名,以保证文档的真实性和完整性。 此过程确保自签署以来文档未被更改。 IronPDF 为此目的提供了一个直接的 API,支持多种应用数字签名的方法。 此功能的核心围绕 PdfSignature 类,封装了证书和签名的所有相关元数据。 签署方法 描述 Sign 用您创建和配置的 PdfSignature 对象 来签署 PDF。 SignWithFile 使用位于磁盘上的数字签名证书文件(.pfx 或 .p12)签署 PDF。 SignWithStore 用计算机证书存储中的数字签名签署 PDF,通过其 指纹 ID 识别。 使用 X509Certificate2 对象 为了最大限度地控制,您可以从您的证书文件创建一个 X509Certificate2 对象。IronPDF 完全符合 X509Certificate2 标准,提供了一种强大且安全的数字签名实现方法。 在创建证书对象时,请确保 X509KeyStorageFlags 设置为 Exportable,因为底层的加密 API 要求如此。 Install-Package IronPdf using IronPdf; using IronPdf.Signing; using System.Security.Cryptography.X509Certificates; // Create a new PDF from an HTML string for demonstration. var renderer = new ChromePdfRenderer(); var pdf = renderer.RenderHtmlAsPdf("<h1>Signed Document</h1><p>This document has been digitally signed.</p>"); // Load the certificate from a .pfx file with its password. // The X509KeyStorageFlags.Exportable flag is crucial for allowing the private key to be used in the signing process. var cert = new X509Certificate2("IronSoftware.pfx", "123456", X509KeyStorageFlags.Exportable); // Create a PdfSignature object using the loaded certificate. var signature = new PdfSignature(cert); // Apply the signature to the PDF document. pdf.Sign(signature); // Save the securely signed PDF document. pdf.SaveAs("Signed.pdf"); using IronPdf; using IronPdf.Signing; using System.Security.Cryptography.X509Certificates; // Create a new PDF from an HTML string for demonstration. var renderer = new ChromePdfRenderer(); var pdf = renderer.RenderHtmlAsPdf("<h1>Signed Document</h1><p>This document has been digitally signed.</p>"); // Load the certificate from a .pfx file with its password. // The X509KeyStorageFlags.Exportable flag is crucial for allowing the private key to be used in the signing process. var cert = new X509Certificate2("IronSoftware.pfx", "123456", X509KeyStorageFlags.Exportable); // Create a PdfSignature object using the loaded certificate. var signature = new PdfSignature(cert); // Apply the signature to the PDF document. pdf.Sign(signature); // Save the securely signed PDF document. pdf.SaveAs("Signed.pdf"); Imports IronPdf Imports IronPdf.Signing Imports System.Security.Cryptography.X509Certificates ' Create a new PDF from an HTML string for demonstration. Private renderer = New ChromePdfRenderer() Private pdf = renderer.RenderHtmlAsPdf("<h1>Signed Document</h1><p>This document has been digitally signed.</p>") ' Load the certificate from a .pfx file with its password. ' The X509KeyStorageFlags.Exportable flag is crucial for allowing the private key to be used in the signing process. Private cert = New X509Certificate2("IronSoftware.pfx", "123456", X509KeyStorageFlags.Exportable) ' Create a PdfSignature object using the loaded certificate. Private signature = New PdfSignature(cert) ' Apply the signature to the PDF document. pdf.Sign(signature) ' Save the securely signed PDF document. pdf.SaveAs("Signed.pdf") $vbLabelText $csharpLabel 上述代码首先生成一个简单的 PDF。 然后它将 .pfx 证书文件加载到 X509Certificate2 对象中。 代表数字身份的该对象传递给 PdfSignature 构造函数。 最后,pdf.Sign 方法在保存文档之前应用此签名。 For more information on the X509Certificate2 class, you can refer to the official Microsoft documentation. 在数字签名中添加细节 一个数字签名可以包含的不仅仅是证书; 您可以嵌入丰富的元数据以提供签名的上下文。 这包括签名位置、原因、联系信息和来自可信机构的安全时间戳。 添加这些细节可以改进文档的审核轨迹,并为验证者提供有价值的信息。 IronPDF 还支持使用现代 SHA256 和 SHA512 哈希算法的时间戳服务器。 using IronPdf; using IronPdf.Signing; using IronSoftware.Drawing; using System; // Load an existing PDF document to be signed. var pdf = PdfDocument.FromFile("invoice.pdf"); // Create a PdfSignature object directly from the certificate file and password. var signature = new PdfSignature("IronSoftware.pfx", "123456"); // Add detailed metadata to the signature for a comprehensive audit trail. signature.SignatureDate = DateTime.Now; signature.SigningContact = "legal@ironsoftware.com"; signature.SigningLocation = "Chicago, USA"; signature.SigningReason = "Contractual Agreement"; // Add a secure timestamp from a trusted Time Stamp Authority (TSA). // This provides cryptographic proof of the signing time. signature.TimeStampUrl = new Uri("[http://timestamp.digicert.com](http://timestamp.digicert.com)"); signature.TimestampHashAlgorithm = TimestampHashAlgorithms.SHA256; // Apply a visual appearance to the signature. (More on this in the next section) signature.SignatureImage = new PdfSignatureImage("assets/visual-signature.png", 0, new Rectangle(350, 750, 200, 100)); // Sign the PDF document with the configured signature object. pdf.Sign(signature); // Save the final, signed PDF document. pdf.SaveAs("DetailedSignature.pdf"); using IronPdf; using IronPdf.Signing; using IronSoftware.Drawing; using System; // Load an existing PDF document to be signed. var pdf = PdfDocument.FromFile("invoice.pdf"); // Create a PdfSignature object directly from the certificate file and password. var signature = new PdfSignature("IronSoftware.pfx", "123456"); // Add detailed metadata to the signature for a comprehensive audit trail. signature.SignatureDate = DateTime.Now; signature.SigningContact = "legal@ironsoftware.com"; signature.SigningLocation = "Chicago, USA"; signature.SigningReason = "Contractual Agreement"; // Add a secure timestamp from a trusted Time Stamp Authority (TSA). // This provides cryptographic proof of the signing time. signature.TimeStampUrl = new Uri("[http://timestamp.digicert.com](http://timestamp.digicert.com)"); signature.TimestampHashAlgorithm = TimestampHashAlgorithms.SHA256; // Apply a visual appearance to the signature. (More on this in the next section) signature.SignatureImage = new PdfSignatureImage("assets/visual-signature.png", 0, new Rectangle(350, 750, 200, 100)); // Sign the PDF document with the configured signature object. pdf.Sign(signature); // Save the final, signed PDF document. pdf.SaveAs("DetailedSignature.pdf"); Imports IronPdf Imports IronPdf.Signing Imports IronSoftware.Drawing Imports System ' Load an existing PDF document to be signed. Private pdf = PdfDocument.FromFile("invoice.pdf") ' Create a PdfSignature object directly from the certificate file and password. Private signature = New PdfSignature("IronSoftware.pfx", "123456") ' Add detailed metadata to the signature for a comprehensive audit trail. signature.SignatureDate = DateTime.Now signature.SigningContact = "legal@ironsoftware.com" signature.SigningLocation = "Chicago, USA" signature.SigningReason = "Contractual Agreement" ' Add a secure timestamp from a trusted Time Stamp Authority (TSA). ' This provides cryptographic proof of the signing time. signature.TimeStampUrl = New Uri("[http://timestamp.digicert.com](http://timestamp.digicert.com)") signature.TimestampHashAlgorithm = TimestampHashAlgorithms.SHA256 ' Apply a visual appearance to the signature. (More on this in the next section) signature.SignatureImage = New PdfSignatureImage("assets/visual-signature.png", 0, New Rectangle(350, 750, 200, 100)) ' Sign the PDF document with the configured signature object. pdf.Sign(signature) ' Save the final, signed PDF document. pdf.SaveAs("DetailedSignature.pdf") $vbLabelText $csharpLabel 如果签名证书不在系统的可信存储中,某些 PDF 查看器中可能会看到警告图标。 要获得绿色勾号,证书必须添加到查看器的可信身份中。 如何为数字签名添加视觉表示? 尽管数字签名是加密嵌入 PDF 中的,但通常在页面上有一个视觉表示是有用的。 这可以是公司徽标、手写签名图像或其他图形。 IronPDF 使添加图像到 PdfSignature 对象中变得简单。 您可以从文件或流中加载图像,并将其精确定位在 PDF 的任何页面上。 支持的图像格式包括 PNG、JPEG、GIF、BMP、TIFF 和 WebP。 using IronPdf.Signing; using IronSoftware.Drawing; // This example demonstrates various ways to add a visual image to a PDF signature. // Create a PdfSignature object. var signature = new PdfSignature("IronSoftware.pfx", "123456"); // Define the position and size for the signature image on the first page (index 0). var signatureRectangle = new Rectangle(350, 750, 200, 100); // Option 1: Set the SignatureImage property directly. signature.SignatureImage = new PdfSignatureImage("assets/visual-signature.png", 0, signatureRectangle); // Option 2: Use the LoadSignatureImageFromFile method. signature.LoadSignatureImageFromFile("assets/visual-signature.png", 0, signatureRectangle); // Option 3: Load an image from a stream. This is useful for images generated in memory. AnyBitmap image = AnyBitmap.FromFile("assets/visual-signature.png"); using (var imageStream = image.ToStream()) { signature.LoadSignatureImageFromStream(imageStream, 0, signatureRectangle); } // After configuring the signature image, apply it to a PDF. var pdf = PdfDocument.FromFile("invoice.pdf"); pdf.Sign(signature); pdf.SaveAs("VisualSignature.pdf"); </span><br class="ProseMirror-trailingBreak"> using IronPdf.Signing; using IronSoftware.Drawing; // This example demonstrates various ways to add a visual image to a PDF signature. // Create a PdfSignature object. var signature = new PdfSignature("IronSoftware.pfx", "123456"); // Define the position and size for the signature image on the first page (index 0). var signatureRectangle = new Rectangle(350, 750, 200, 100); // Option 1: Set the SignatureImage property directly. signature.SignatureImage = new PdfSignatureImage("assets/visual-signature.png", 0, signatureRectangle); // Option 2: Use the LoadSignatureImageFromFile method. signature.LoadSignatureImageFromFile("assets/visual-signature.png", 0, signatureRectangle); // Option 3: Load an image from a stream. This is useful for images generated in memory. AnyBitmap image = AnyBitmap.FromFile("assets/visual-signature.png"); using (var imageStream = image.ToStream()) { signature.LoadSignatureImageFromStream(imageStream, 0, signatureRectangle); } // After configuring the signature image, apply it to a PDF. var pdf = PdfDocument.FromFile("invoice.pdf"); pdf.Sign(signature); pdf.SaveAs("VisualSignature.pdf"); </span><br class="ProseMirror-trailingBreak"> Imports IronPdf.Signing Imports IronSoftware.Drawing ' This example demonstrates various ways to add a visual image to a PDF signature. ' Create a PdfSignature object. Private signature = New PdfSignature("IronSoftware.pfx", "123456") ' Define the position and size for the signature image on the first page (index 0). Private signatureRectangle = New Rectangle(350, 750, 200, 100) ' Option 1: Set the SignatureImage property directly. signature.SignatureImage = New PdfSignatureImage("assets/visual-signature.png", 0, signatureRectangle) ' Option 2: Use the LoadSignatureImageFromFile method. signature.LoadSignatureImageFromFile("assets/visual-signature.png", 0, signatureRectangle) ' Option 3: Load an image from a stream. This is useful for images generated in memory. Dim image As AnyBitmap = AnyBitmap.FromFile("assets/visual-signature.png") Using imageStream = image.ToStream() signature.LoadSignatureImageFromStream(imageStream, 0, signatureRectangle) End Using ' After configuring the signature image, apply it to a PDF. Dim pdf = PdfDocument.FromFile("invoice.pdf") pdf.Sign(signature) pdf.SaveAs("VisualSignature.pdf") 'INSTANT VB TODO TASK: The following line uses invalid syntax: '</span><br class="ProseMirror-trailingBreak"> $vbLabelText $csharpLabel 此代码展示了三种等效的方法来为数字签名添加视觉组件。 无论您是有一个磁盘上的图像还是在内存中的图像,都可以轻松地作为签名过程的一部分将它加盖到 PDF 上。 这弥合了不可见的加密安全性和可见的文档批准之间的差距。 签署后如何控制文档权限? 当您签署文档时,您可能想要指定在签署后可允许的更改。 例如,您可能希望完全锁定文档,或仅允许用户填写表单字段。 IronPDF 允许您使用 SignaturePermissions 枚举来设置这些权限。 设置签名权限是管理文档生命周期的关键部分。 它确保在应用签名后根据您的规则维护文档的完整性。 如果用户执行了不允许的操作,签名将失效。 SignaturePermissions 成员 定义 NoChangesAllowed 不允许任何种类的更改。文档实际上被锁定。 FormFillingAllowed 仅允许填写现有的表单字段和签名。 AnnotationsAndFormFillingAllowed 允许填写表单、签名以及创建或修改注释。 保存特定的 PDF 修订版并签署 PDF 可以存储更改历史,就像版本控制系统一样。 这被称为增量保存。 当您签署 PDF 时,签名适用于文档的特定修订。 这对于文档经过多个审批阶段的工作流程至关重要。 在以下示例中,我们加载一个 PDF,进行编辑,然后签署当前修订版,同时仅允许在未来进行表单填充。 我们使用 SaveAsRevision 将当前状态提交到文档的历史中,然后保存文件。 using IronPdf.Signing; // Load a PDF file with change tracking enabled. var pdf = PdfDocument.FromFile("annual_census.pdf", ChangeTrackingModes.EnableChangeTracking); // Placeholder for edits: You might add text, fill forms, or add annotations here. // For example: pdf.Annotations.Add(new TextAnnotation(...)); // Sign the current state of the document using SignWithFile for convenience. // We set permissions to allow further signatures and form filling. pdf.SignWithFile( "assets/IronSignature.p12", "password", SignaturePermissions.AdditionalSignaturesAndFormFillingAllowed); // Save the current state as a distinct revision within the PDF's history. PdfDocument pdfWithRevision = pdf.SaveAsRevision(); // Save the final PDF with its full revision history to a new file. pdfWithRevision.SaveAs("annual_census_signed.pdf"); using IronPdf.Signing; // Load a PDF file with change tracking enabled. var pdf = PdfDocument.FromFile("annual_census.pdf", ChangeTrackingModes.EnableChangeTracking); // Placeholder for edits: You might add text, fill forms, or add annotations here. // For example: pdf.Annotations.Add(new TextAnnotation(...)); // Sign the current state of the document using SignWithFile for convenience. // We set permissions to allow further signatures and form filling. pdf.SignWithFile( "assets/IronSignature.p12", "password", SignaturePermissions.AdditionalSignaturesAndFormFillingAllowed); // Save the current state as a distinct revision within the PDF's history. PdfDocument pdfWithRevision = pdf.SaveAsRevision(); // Save the final PDF with its full revision history to a new file. pdfWithRevision.SaveAs("annual_census_signed.pdf"); Imports IronPdf.Signing ' Load a PDF file with change tracking enabled. Private pdf = PdfDocument.FromFile("annual_census.pdf", ChangeTrackingModes.EnableChangeTracking) ' Placeholder for edits: You might add text, fill forms, or add annotations here. ' For example: pdf.Annotations.Add(new TextAnnotation(...)); ' Sign the current state of the document using SignWithFile for convenience. ' We set permissions to allow further signatures and form filling. pdf.SignWithFile("assets/IronSignature.p12", "password", SignaturePermissions.AdditionalSignaturesAndFormFillingAllowed) ' Save the current state as a distinct revision within the PDF's history. Dim pdfWithRevision As PdfDocument = pdf.SaveAsRevision() ' Save the final PDF with its full revision history to a new file. pdfWithRevision.SaveAs("annual_census_signed.pdf") $vbLabelText $csharpLabel 理解增量保存是高级 PDF 工作流程的关键。 虽然简单查看器可能只会显示最新版本,但像 Adobe Acrobat 这样的工具可以显示完整的修订历史,展示谁签署了哪个版本以及各签名间做了哪些更改。 IronPDF 使您可以完全以编程方式控制这一过程。 对于需要高安全性和合规性的复杂文档工作流程,企业可能需要一个全面的解决方案。 Iron Software 提供 Iron Suite,其中包括用于签署和操作的 IronPDF,以及用于广泛文档处理任务的其他库,仅需一次性购买费用。 如何管理和验证跨修订版的签名? 一个 PDF 文档可以在其各种修订版中应用多个签名。 IronPDF 提供工具来有效地管理这个历史。 回滚到先前的修订版:您可以使用 GetRevision 方法将文档还原到较早的状态。 这将丢弃该修订之后的所有更改和签名。 验证所有签名:VerifySignatures 方法检查文档所有修订的所有签名的有效性。 仅当每个签名都有效且没有未经授权的更改时,它才返回 true。 移除签名:RemoveSignatures 方法将去除文档每个修订的所有数字签名,生成一个清洁的、无签名的版本。 // Load a PDF with a complex signature history. var pdf = PdfDocument.FromFile("multi_signed_report.pdf"); // Verify all signatures across all revisions. bool allSignaturesValid = pdf.VerifySignatures(); Console.WriteLine($"All signatures are valid: {allSignaturesValid}"); // Roll back to the first revision (index 0). if (pdf.RevisionCount > 1) { PdfDocument firstRevision = pdf.GetRevision(0); firstRevision.SaveAs("report_first_revision.pdf"); } // Create a completely unsigned version of the document. pdf.RemoveSignatures(); pdf.SaveAs("report_unsigned.pdf"); // Load a PDF with a complex signature history. var pdf = PdfDocument.FromFile("multi_signed_report.pdf"); // Verify all signatures across all revisions. bool allSignaturesValid = pdf.VerifySignatures(); Console.WriteLine($"All signatures are valid: {allSignaturesValid}"); // Roll back to the first revision (index 0). if (pdf.RevisionCount > 1) { PdfDocument firstRevision = pdf.GetRevision(0); firstRevision.SaveAs("report_first_revision.pdf"); } // Create a completely unsigned version of the document. pdf.RemoveSignatures(); pdf.SaveAs("report_unsigned.pdf"); ' Load a PDF with a complex signature history. Dim pdf = PdfDocument.FromFile("multi_signed_report.pdf") ' Verify all signatures across all revisions. Dim allSignaturesValid As Boolean = pdf.VerifySignatures() Console.WriteLine($"All signatures are valid: {allSignaturesValid}") ' Roll back to the first revision (index 0). If pdf.RevisionCount And gt; 1 Then Dim firstRevision As PdfDocument = pdf.GetRevision(0) firstRevision.SaveAs("report_first_revision.pdf") End If ' Create a completely unsigned version of the document. pdf.RemoveSignatures() pdf.SaveAs("report_unsigned.pdf") $vbLabelText $csharpLabel 如何在 PDF 上加盖手写签名? 有时,您不需要数字签名的加密安全性,而只是想应用一个视觉的、电子的签名,比如扫描的手写签名。 这通常被称为 stamping。 IronPDF 可以使用其 Watermark 或 Stamp 功能来做到这一点。 让我们以一个示例发票 PDF 和一个 .png 的手写签名图像开始。 在加盖签名之前的原始发票 PDF 。 这是我们将要应用的签名图像: 一个示例手写签名图像. 以下代码使用 Watermark 属性将该图像加盖在 PDF 的右下角。 using IronPdf.Editing; // Load the existing PDF document. var pdf = PdfDocument.FromFile("invoice.pdf"); // Create an HtmlStamp containing our signature image. var signatureStamp = new HtmlStamp("<img src='assets/signature.png'/>") { // Configure the stamp's position and appearance. VerticalAlignment = VerticalAlignment.Bottom, HorizontalAlignment = HorizontalAlignment.Right, Margin = 10, // Add some space from the edge. Opacity = 90 // Make it slightly transparent. }; // Apply the stamp to all pages of the PDF. pdf.ApplyStamp(signatureStamp); // Save the modified PDF document. pdf.SaveAs("official_invoice.pdf"); using IronPdf.Editing; // Load the existing PDF document. var pdf = PdfDocument.FromFile("invoice.pdf"); // Create an HtmlStamp containing our signature image. var signatureStamp = new HtmlStamp("<img src='assets/signature.png'/>") { // Configure the stamp's position and appearance. VerticalAlignment = VerticalAlignment.Bottom, HorizontalAlignment = HorizontalAlignment.Right, Margin = 10, // Add some space from the edge. Opacity = 90 // Make it slightly transparent. }; // Apply the stamp to all pages of the PDF. pdf.ApplyStamp(signatureStamp); // Save the modified PDF document. pdf.SaveAs("official_invoice.pdf"); Imports IronPdf.Editing ' Load the existing PDF document. Private pdf = PdfDocument.FromFile("invoice.pdf") ' Create an HtmlStamp containing our signature image. Dim signatureStamp = New HtmlStamp("<img src='assets/signature.png'/>") If True Then ' Configure the stamp's position and appearance. 'INSTANT VB WARNING: An assignment within expression was extracted from the following statement: 'ORIGINAL LINE: VerticalAlignment = VerticalAlignment.Bottom, HorizontalAlignment = HorizontalAlignment.Right, Margin = 10, Opacity = 90 10, Opacity = 90 ' Make it slightly transparent. 'INSTANT VB WARNING: An assignment within expression was extracted from the following statement: 'ORIGINAL LINE: VerticalAlignment = VerticalAlignment.Bottom, HorizontalAlignment = HorizontalAlignment.Right, Margin = 10, Opacity HorizontalAlignment.Right, Margin = 10, Opacity 'INSTANT VB WARNING: An assignment within expression was extracted from the following statement: 'ORIGINAL LINE: VerticalAlignment = VerticalAlignment.Bottom, HorizontalAlignment = HorizontalAlignment.Right, Margin VerticalAlignment.Bottom, HorizontalAlignment = HorizontalAlignment.Right, Margin VerticalAlignment = VerticalAlignment.Bottom, HorizontalAlignment End If ' Apply the stamp to all pages of the PDF. pdf.ApplyStamp(signatureStamp) ' Save the modified PDF document. pdf.SaveAs("official_invoice.pdf") $vbLabelText $csharpLabel 加盖 PDF 结果 运行代码后,签名图像被加盖到文档上,创建了一个可视签名的发票。 最终带有右下角手写签名图像加盖的 PDF. 如何在 PDF 上添加交互式签名字段? 对于需要在像 Adobe Acrobat 这样的 PDF 查看器中由最终用户签署的文档,您可以添加一个交互式签名表单字段。 这就创建了一个空的、可点击的区域,提示用户应用他们自己的数字签名。 您可以创建一个 SignatureFormField 并将其添加到 PDF 的表单集中。 您可以精确控制其在页面上的位置和大小。 using IronPdf.Forms; using IronSoftware.Drawing; // Create a new PDF to add the signature field to. var renderer = new ChromePdfRenderer(); var pdf = renderer.RenderHtmlAsPdf("<h1>Please Sign Below</h1>"); // Define the properties for the signature form field. string fieldName = "ClientSignature"; int pageIndex = 0; // Add to the first page. var fieldRect = new Rectangle(50, 200, 300, 100); // Position: (x, y), Size: (width, height) // Create the SignatureFormField object. var signatureField = new SignatureFormField(fieldName, pageIndex, fieldRect); // Add the signature field to the PDF's form. pdf.Form.Add(signatureField); // Save the PDF with the new interactive signature field. pdf.SaveAs("interactive_signature.pdf"); using IronPdf.Forms; using IronSoftware.Drawing; // Create a new PDF to add the signature field to. var renderer = new ChromePdfRenderer(); var pdf = renderer.RenderHtmlAsPdf("<h1>Please Sign Below</h1>"); // Define the properties for the signature form field. string fieldName = "ClientSignature"; int pageIndex = 0; // Add to the first page. var fieldRect = new Rectangle(50, 200, 300, 100); // Position: (x, y), Size: (width, height) // Create the SignatureFormField object. var signatureField = new SignatureFormField(fieldName, pageIndex, fieldRect); // Add the signature field to the PDF's form. pdf.Form.Add(signatureField); // Save the PDF with the new interactive signature field. pdf.SaveAs("interactive_signature.pdf"); Imports IronPdf.Forms Imports IronSoftware.Drawing ' Create a new PDF to add the signature field to. Private renderer = New ChromePdfRenderer() Private pdf = renderer.RenderHtmlAsPdf("<h1>Please Sign Below</h1>") ' Define the properties for the signature form field. Private fieldName As String = "ClientSignature" Private pageIndex As Integer = 0 ' Add to the first page. Private fieldRect = New Rectangle(50, 200, 300, 100) ' Position: (x, y), Size: (width, height) ' Create the SignatureFormField object. Private signatureField = New SignatureFormField(fieldName, pageIndex, fieldRect) ' Add the signature field to the PDF's form. pdf.Form.Add(signatureField) ' Save the PDF with the new interactive signature field. pdf.SaveAs("interactive_signature.pdf") $vbLabelText $csharpLabel 当用户打开这个 PDF 时,他们会看到一个可点击的字段,允许他们使用自己的数字 ID 完成签署过程。 您可以在我们的 如何创建 PDF 表单指南中了解有关创建和管理交互式表单的更多信息。 程序化添加到 PDF 文档的未签名、交互式签名字段. 如何从已验证的签名中获取签名者名称 为了获得签名者的证书拥有者的常用名,我们可以使用 VerifiedSignature 类访问 SignerName 属性。 下面是一个代码片段,展示了如何完成此操作。 :path=/static-assets/pdf/content-code-examples/how-to/signing-find-signer-name.cs using IronPdf; using System; // Import the Signed PDF report var pdf = PdfDocument.FromFile("multi_signed_report.pdf"); // Using GetVerifiedSignatures() obtain a list of `VerifiedSignature` objects from the PDF pdf.GetVerifiedSignatures().ForEach(signature => { // Print out the SignerName of each `VerifiedSignature` object Console.WriteLine($"SignatureName: {signature.SignerName}"); }); IRON VB CONVERTER ERROR developers@ironsoftware.com $vbLabelText $csharpLabel 在导入签名的 PDF 文件后,我们利用 GetVerifiedSignatures 方法检索报告中的 VerifiedSignature 对象列表,并打印每个签名的 SignerName。 请注意请注意,此值是从证书的主体识别名 (SubjectDN) 中提取的,如果 CN 字段不存在,则将返回 null。 下一步 本指南演示了 IronPDF 的强大和灵活的 PDF 签名功能。 无论您是需要应用带有详细元数据的安全数字签名、管理文档修订、加盖可视签名还是创建交互式表单,IronPDF 提供了一个全面且开发者友好的 API 来完成此任务。 To continue exploring, you can download the IronPDF library for .NET and get a free trial license to test out all its features in your projects. 准备好看看您还能做些什么吗? 查看我们的教程页面:签名和保护PDFs 常见问题解答 如何在C#中使用证书文件为PDF应用数字签名? 要在C#中使用证书文件为PDF应用数字签名,可以利用IronPDF。将您的证书加载到X509Certificate2对象,并使用IronPDF的PdfSignature类通过Sign方法应用它到您的文档。 使用数字签名进行PDF文档的好处是什么? 数字签名为PDF文档提供了认证和完整性。通过使用IronPDF,您可以确保您的文档由经过验证的源签名,并且自应用签名以来未曾更改。 如何在C#中向PDF添加手写签名? IronPDF允许您通过将签名图像盖章到PDF上来添加手写签名。您可以使用ApplyStamp方法和HtmlStamp,指定图像文件来实现这一点。 在PDF中添加交互式签名字段的过程是什么? 要在PDF中添加交互式签名字段,创建一个SignatureFormField对象,指定所需的名称、页面和位置。在保存文档之前,使用IronPDF将此字段添加到PdfDocument.Form集合中。 我可以控制已签名PDF的权限吗? 可以,当使用IronPDF签署PDF时,您可以指定SignaturePermissions来控制签名后允许的更改。选项包括NoChangesAllowed、FormFillingAllowed和AnnotationsAndFormFillingAllowed。 如何验证PDF的数字签名的真实性? IronPDF提供了一个VerifySignatures方法,用于检查PDF中所有签名的有效性。它返回一个布尔值,指示所有签名是否真实并且没有被篡改。 PDF中的增量保存是什么以及为何有用? PDF中的增量保存允许多个文档版本存储在单个文件中。此功能有助于维护变更历史记录,并确保每个数字签名与签名时的正确文档版本对应。 如何在PDF的数字签名中添加元数据? 使用IronPDF,您可以在创建PdfSignature对象时设置签署原因、位置和时间戳等元数据,从而为签署过程提供详细的文档记录。 我可以在 .NET 10 应用程序中使用 IronPDF 的数字签名功能吗? 是的。IronPDF 完全支持 .NET 10,因此本文中展示的基于 X509Certificate2 的数字签名工作流程可以在 .NET 10 控制台、Web 和服务应用程序中使用。只需创建一个 .NET 10 项目,从 NuGet 安装最新的 IronPdf 软件包,并重用签名代码即可应用不可见或可见签名、签名图像和签名表单字段。 Jacob Mellor 立即与工程团队聊天 首席技术官 Jacob Mellor 是 Iron Software 的首席技术官,是 C# PDF 技术的先锋工程师。作为 Iron Software 核心代码库的原始开发者,自公司成立以来,他就塑造了公司的产品架构,并与首席执行官 Cameron Rimington 一起将其转变成一家公司,拥有50多人,服务于 NASA、特斯拉和全球政府机构。Jacob 拥有曼彻斯特大学 (1998-2001) 的一级荣誉土木工程学士学位。1999 年在伦敦创办了自己的第一家软件公司,并于 2005 年创建了他的第一个 .NET 组件后,他专注于解决微软生态系统中的复杂问题。他的旗舰 IronPDF 和 IronSuite .NET 库在全球已获得超过 3000 万次的 NuGet 安装,其基础代码继续为全球使用的开发者工具提供支持。拥有 25 年商业经验和 41 年编程经验的 Jacob 仍专注于推动企业级 C#、Java 和 Python PDF 技术的创新,同时指导下一代技术领导者。 审核者 Jeffrey T. Fritz 首席项目经理 - .NET 社区团队 Jeff 也是 .NET 和 Visual Studio 团队的首席项目经理。他是 .NET Conf 虚拟会议系列的执行制片人,并主持“Fritz and Friends”直播节目,每周两次与观众一起谈论技术并编写代码。Jeff 撰写研讨会、演示文稿并计划包括 Microsoft Build、Microsoft Ignite、.NET Conf 和 Microsoft MVP 峰会在内的最大型微软开发者活动的内容。 准备开始了吗? Nuget 下载 16,154,058 | 版本: 2025.11 刚刚发布 免费 NuGet 下载 总下载量:16,154,058 查看许可证