如何使用 IronPDF 在 C# 中簽署 PDF 文件 | IronPDF 教程

使用 C# 對 PDF 進行數位簽章的開發人員指南

This article was translated from English: Does it need improvement?
Translated
View the article in English

本綜合指南向 C# 開發人員展示了如何使用 IronPDF 對 PDF 進行數位簽名,內容涵蓋了基於證書的簽名、視覺戳記和互動表單欄位,以確保文檔的真實性和安全性。

在許多應用程式中,向 PDF 文件添加簽名是一項常見要求,但"簽名"的含義可能有所不同。 對某些人來說,關鍵在於使用安全憑證應用防篡改的數位簽章。 對於其他人來說,這可能是在文件上蓋上手寫簽名圖像,或者添加一個互動式表單欄位供使用者進行電子簽名。

本指南為 C# 開發人員提供了使用IronPDF for .NET 程式庫完成所有這些任務的全面演練。 我們將涵蓋從應用安全的X509Certificate2數位簽章到新增圖形簽章和建立互動式簽章網域的所有內容,確保您的 PDF 文件真實、安全且專業。

快速入門:使用 IronPDF 輕鬆地對 PDF 進行數位簽章

使用 IronPDF,透過簡單直接的流程,即可快速開始對 PDF 文件進行數位簽章。 本範例示範如何使用 .pfx 憑證對 PDF 檔案進行驗證和簽名,以確保文件的完整性和真實性。 請遵循以下步驟,將數位簽章無縫整合至您的應用程式。

Nuget Icon立即開始使用 NuGet 建立 PDF 檔案:

  1. 使用 NuGet 套件管理器安裝 IronPDF

    PM > Install-Package IronPdf

  2. 複製並運行這段程式碼。

    new IronPdf.Signing.PdfSignature("certificate.pfx", "password").SignPdfFile("input.pdf");
  3. 部署到您的生產環境進行測試

    立即開始在您的專案中使用 IronPDF,免費試用!
    arrow pointer

如何將數位簽章應用於具有憑證的 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");
$vbLabelText   $csharpLabel

上面的程式碼首先產生一個簡單的PDF檔案。 然後它將.pfx憑證檔案載入到X509Certificate2物件中。 此物件代表數位身份,並傳遞給PdfSignature建構函數。 最後, pdf.Sign方法會在儲存文件之前將此簽章套用到文件上。 For more information on the X509Certificate2 class, you can refer to the official Microsoft documentation.

為數位簽名添加詳細信息

數位簽章可以包含憑證以外的內容; 您可以嵌入豐富的元數據,以提供有關簽名的上下文資訊。 這包括簽署地點、原因、聯絡資訊以及來自可信任機構的安全時間戳。 您也可以設定和編輯元資料,以取得額外的文件屬性。

添加這些細節可以改進文件的審計跟踪,並為核實人員提供有價值的資訊。 IronPDF 也支援使用現代SHA256SHA512雜湊演算法的時間戳伺服器。

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.
// These properties enhance the signature's credibility and provide context
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.
// These properties enhance the signature's credibility and provide context
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。此技術與您在 PDF 文件上標示文字和影像的方式類似。

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).
// Rectangle parameters: x position, y position, width, height
var signatureRectangle = new Rectangle(350, 750, 200, 100);

// Option 1: Set the SignatureImage property directly.
// This is the most straightforward approach
signature.SignatureImage = new PdfSignatureImage("assets/visual-signature.png", 0, signatureRectangle);

// Option 2: Use the LoadSignatureImageFromFile method.
// This method provides the same functionality with a different syntax
signature.LoadSignatureImageFromFile("assets/visual-signature.png", 0, signatureRectangle);

// Option 3: Load an image from a stream. This is useful for images generated in memory.
// Perfect for scenarios where images are retrieved from databases or web services
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");
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).
// Rectangle parameters: x position, y position, width, height
var signatureRectangle = new Rectangle(350, 750, 200, 100);

// Option 1: Set the SignatureImage property directly.
// This is the most straightforward approach
signature.SignatureImage = new PdfSignatureImage("assets/visual-signature.png", 0, signatureRectangle);

// Option 2: Use the LoadSignatureImageFromFile method.
// This method provides the same functionality with a different syntax
signature.LoadSignatureImageFromFile("assets/visual-signature.png", 0, signatureRectangle);

// Option 3: Load an image from a stream. This is useful for images generated in memory.
// Perfect for scenarios where images are retrieved from databases or web services
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");
$vbLabelText   $csharpLabel

這段程式碼展示了三種向數位簽名添加視覺組件的等效方法。 無論影像儲存在磁碟還是記憶體中,您都可以在簽名過程中輕鬆地將其添加到 PDF 檔案中。 這彌合了無形的加密安全性和可見的文件審批之間的差距。

簽名後如何控製文件權限?

簽署文件時,您可能需要明確規定之後允許進行哪些更改(如果有的話)。 例如,您可能希望完全鎖定文檔,或只允許使用者填寫表單欄位。 IronPDF 讓您可以使用SignaturePermissions枚舉來設定這些權限。 如需更進階的權限控制,請參閱我們的 設定 PDF 密碼和權限指南。

設定簽名權限是管理文件生命週期的關鍵環節。 它確保在您簽署後,文件的完整性能夠按照您的規定得到維護。 如果使用者執行了不允許的操作,則簽名將失效。

SignaturePermissions成員定義
不允許更改不允許進行任何形式的更改。該文件已被鎖定。
<代碼>FormFillingAllowed僅允許填寫現有表單欄位和簽名。
允許註解和填表允許填寫表單、簽名以及建立或修改註釋。

Saving and Signing a Specific PDF Revision

PDFs can store a history of changes, much like a version control system. This is known as incremental saving. When you sign a PDF, the signature applies to a specific revision of the document. This is crucial for workflows where a document goes through multiple stages of approval. Learn more about managing PDF revision history in our detailed guide.

In the following example, we load a PDF, make edits, and then sign the current revision while allowing only form-filling as a future change. We use SaveAsRevision to commit the current state to the document's history before saving the file.

using IronPdf.Signing;

// Load a PDF file with change tracking enabled.
// This enables incremental save functionality for revision management
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(...));
// Or: pdf.Form["fieldName"].Value = "New Value";

// 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.
// This creates a snapshot that can be referenced later
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.
// This enables incremental save functionality for revision management
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(...));
// Or: pdf.Form["fieldName"].Value = "New Value";

// 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.
// This creates a snapshot that can be referenced later
PdfDocument pdfWithRevision = pdf.SaveAsRevision();

// Save the final PDF with its full revision history to a new file.
pdfWithRevision.SaveAs("annual_census_signed.pdf");
$vbLabelText   $csharpLabel

Understanding incremental saves is key to advanced PDF workflows. While a simple viewer might only show the latest version, a tool like Adobe Acrobat can reveal the entire revision history, showing who signed which version and what changes were made between signatures. IronPDF gives you full programmatic control over this process.

For businesses managing complex document workflows that require high security and compliance, a comprehensive solution may be needed. Iron Software offers Iron Suite, which includes IronPDF for signing and manipulation, plus other libraries for a wide range of document processing tasks, available for a single one-time payment.

How Can I Manage and Verify Signatures Across Revisions?

A PDF document can have multiple signatures applied across its various revisions. IronPDF provides tools to manage this history effectively.

  • Roll Back to a Previous Revision: You can revert a document to an earlier state using the GetRevision method. This will discard all changes and signatures made after that revision.
  • Verify All Signatures: The VerifySignatures method checks the validity of all signatures across all revisions of the document. It returns true only if every signature is valid and no unauthorized changes have been made.
  • Remove Signatures: The RemoveSignatures method will strip all digital signatures from every revision of the document, creating a clean, unsigned version.
// Load a PDF with a complex signature history.
var pdf = PdfDocument.FromFile("multi_signed_report.pdf");

// Verify all signatures across all revisions.
// This ensures document integrity throughout its entire history
bool allSignaturesValid = pdf.VerifySignatures();
Console.WriteLine($"All signatures are valid: {allSignaturesValid}");

// Roll back to the first revision (index 0).
// Useful for reviewing the original document state
if (pdf.RevisionCount &gt; 1)
{
    PdfDocument firstRevision = pdf.GetRevision(0);
    firstRevision.SaveAs("report_first_revision.pdf");
}

// Create a completely unsigned version of the document.
// This removes all digital signatures while preserving content
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.
// This ensures document integrity throughout its entire history
bool allSignaturesValid = pdf.VerifySignatures();
Console.WriteLine($"All signatures are valid: {allSignaturesValid}");

// Roll back to the first revision (index 0).
// Useful for reviewing the original document state
if (pdf.RevisionCount &gt; 1)
{
    PdfDocument firstRevision = pdf.GetRevision(0);
    firstRevision.SaveAs("report_first_revision.pdf");
}

// Create a completely unsigned version of the document.
// This removes all digital signatures while preserving content
pdf.RemoveSignatures();
pdf.SaveAs("report_unsigned.pdf");
$vbLabelText   $csharpLabel

How Do I Stamp a Handwritten Signature onto a PDF?

Sometimes, you don't need the cryptographic security of a digital signature but simply want to apply a visual, electronic signature, like a scanned handwritten signature. This is often referred to as stamping. IronPDF can do this using its Watermark or Stamp features. For more advanced watermarking options, explore our custom watermarks guide.

Let's start with a sample invoice PDF and a .png image of a handwritten signature.

The original invoice PDF before stamping a signature.

Here is the signature image we will apply:

Handwritten signature sample showing 'IRON' in black ink for PDF stamping tutorial A sample handwritten signature image.

The following code uses the Watermark property to stamp this image onto the bottom-right corner of the PDF.

using IronPdf.Editing;

// Load the existing PDF document.
var pdf = PdfDocument.FromFile("invoice.pdf");

// Create an HtmlStamp containing our signature image.
// HtmlStamp allows us to position HTML content precisely on the page
var signatureStamp = new HtmlStamp("&lt;img src='assets/signature.png'/&gt;")
{
    // 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 for a more authentic look.
};

// Apply the stamp to all pages of the PDF.
// You can also specify specific page numbers if needed
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.
// HtmlStamp allows us to position HTML content precisely on the page
var signatureStamp = new HtmlStamp("&lt;img src='assets/signature.png'/&gt;")
{
    // 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 for a more authentic look.
};

// Apply the stamp to all pages of the PDF.
// You can also specify specific page numbers if needed
pdf.ApplyStamp(signatureStamp);

// Save the modified PDF document.
pdf.SaveAs("official_invoice.pdf");
$vbLabelText   $csharpLabel

What Does the Stamped PDF Result Look Like?

After running the code, the signature image is stamped onto the document, creating a visually signed invoice.

The final PDF with the handwritten signature image stamped in the bottom-right corner.

How Can I Add an Interactive Signature Field to a PDF?

For documents that need to be signed by an end-user in a PDF viewer like Adobe Acrobat, you can add an interactive signature form field. This creates an empty, clickable area that prompts the user to apply their own digital signature. For a complete guide on PDF forms, see our creating PDF forms tutorial.

You can create a SignatureFormField and add it to the PDF's form collection. You have precise control over its location and size on the page. This is particularly useful for documents that require multiple signatures or when you need to collect signatures from external parties.

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>請在下方簽名</h1>");

// Define the properties for the signature form field.
string fieldName = "ClientSignature";  // Unique identifier for the field
int pageIndex = 0;  // Add to the first page (zero-indexed)
var fieldRect = new Rectangle(50, 200, 300, 100);  // Position: (x, y), Size: (width, height)

// Create the SignatureFormField object.
// This creates an interactive field that users can click to sign
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>請在下方簽名</h1>");

// Define the properties for the signature form field.
string fieldName = "ClientSignature";  // Unique identifier for the field
int pageIndex = 0;  // Add to the first page (zero-indexed)
var fieldRect = new Rectangle(50, 200, 300, 100);  // Position: (x, y), Size: (width, height)

// Create the SignatureFormField object.
// This creates an interactive field that users can click to sign
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");
$vbLabelText   $csharpLabel

When a user opens this PDF, they will see a clickable field, allowing them to complete the signing process using their own digital ID. You can learn more about creating and managing interactive forms in our How-To guide on creating PDF forms.

PDF editor showing unsigned signature field with 'Click to sign' prompt in document titled 'testing' An unsigned, interactive signature field added programmatically to a PDF document.

How Do I Retrieve the Signer Name from Verified Signatures?

To obtain the common name of the certificate owner who signed a signature, we can use the VerifiedSignature class to access the SignerName property. Below is a code snippet demonstrating how to accomplish this.

: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}");
});
$vbLabelText   $csharpLabel

匯入已簽署的 PDF 檔案後,我們利用 GetVerifiedSignatures 方法擷取報告中的 VerifiedSignature 物件清單,並列印每個簽章的 SignerName

請注意,此值是從證書的主體識別名(SubjectDN)中提取出來的,如果 CN 欄位不存在,將返回空值。

使用 IronPDF 進行 PDF 簽署的下一步是什麼?

本指南展示了 IronPDF 强大而灵活的 PDF 签名功能。無論您是需要應用具有詳細元資料的安全數位簽章、管理文檔修訂、加蓋可視簽章,還是創建交互式表單,IronPDF 都能提供全面且開發人員友好的 API 來完成工作。

若要繼續探索,您可以下載 IronPDF library for .NET 並取得 免費試用授權,以便在您的專案中測試其所有功能。如需更多進階的文件操作技術,包括 加入註解 和使用表格欄位,請參閱我們廣泛的文件和教學。

準備好看看您還能做什麼嗎?請按這裡查看我們的教學頁面:簽署和保護 PDF

常見問題解答

如何在 C# 中使用憑證對 PDF 進行數位簽章?

使用 IronPDF,您只需使用 PdfSignature 類一行代碼即可對 PDF 進行數位簽名。只需用您的證書文件(.pfx 或 .p12)和密碼創建一個新的 PdfSignature 物件,然後調用 SignPdfFile() 方法。例如:new IronPDF.Signing.PdfSignature("certificate.pfx", "password").SignPdfFile("input.pdf")。這將使用您的 X509Certificate2 套用防篡改數位簽章,以確保文件的真實性。

支援哪些類型的 PDF 簽名?

IronPDF 支持三种主要的 PDF 签名类型:1) 使用 X509Certificate2 憑證進行驗證和防篡改的數位簽章;2) 在文件中添加圖形或手寫簽名圖像的視覺簽章;以及 3) 允許用戶對 PDF 進行電子簽名的互動簽名表單欄位。每種類型對於文件安全性和工作流程需求都有不同的用途。

哪些憑證格式可用於數位簽章?

IronPdf 支援常見的數位憑證格式,包括 .pfx(個人資訊交換)和 .p12 檔案。這些證書檔案包含數位簽章所需的公開金鑰和私人金鑰。IronPdf 中的 PdfSignature 類別可以與任何 X509Certificate2 物件一起工作,為您加載和管理簽名證書提供了靈活性。

我可以在數位簽章中加入視覺表示嗎?

是的,IronPDF 允許您在數位簽名中加入視覺元素。您可以在加密簽章旁加入圖形表示,例如手寫簽章圖像、公司標誌或自訂印章。這將數位憑證的安全性與視覺確認結合起來,使簽署的文件既安全又具有專業性。

如何建立互動式簽名欄位供使用者進行電子簽名?

IronPDF 可讓您在 PDF 文件中加入互動式簽名表單欄位。這些欄位允許使用者透過點擊並繪製簽名或上傳簽名影像,以電子方式簽署文件。此功能非常適合建立需要收集簽名的文件,例如需要多方簽名的合約或表格。

簽署 PDF 是否能確保文件的完整性?

是的,當您使用 IronPDF 以 X509Certificate2 對 PDF 進行數位簽章時,會建立一個防篡改的封印,以確保文件的完整性。數位簽章保證文件自簽署後未被修改。簽名後對 PDF 的任何修改都會使簽名失效,提醒收件人該文件可能已被洩露。

Jacob Mellor,Team Iron 首席技術官
首席技術長

Jacob Mellor 是 Iron Software 的首席技術官,也是一位富有遠見的工程師,率先開發了 C# PDF 技術。作為 Iron Software 核心程式碼庫的最初開發者,他自公司成立之初便參與塑造了其產品架構,並與執行長 Cameron Rimington 一起將其發展成為一家擁有 50 多名員工、服務於 NASA、特斯拉和全球政府機構的公司。

Jacob 於 1998 年至 2001 年在曼徹斯特大學獲得土木工程一級榮譽學士學位。 1999 年,他在倫敦創辦了自己的第一家軟體公司;2005 年,他創建了自己的第一個 .NET 元件。此後,他專注於解決微軟生態系統中的複雜問題。

他的旗艦產品 IronPDF 和 IronSuite .NET 庫在全球 NuGet 上的安裝量已超過 3000 萬次,其基礎程式碼持續為全球開發者工具提供支援。憑藉 25 年的商業經驗和 41 年的程式設計專長,Jacob 始終致力於推動企業級 C#、Java 和 Python PDF 技術的創新,同時指導下一代技術領導者。

經審核
傑夫·弗里茨
傑弗裡·T·弗里茨
.NET 社群團隊首席專案經理
Jeff 同時也是 .NET 和 Visual Studio 團隊的首席專案經理。他是 .NET Conf 虛擬會議系列的執行製片人,並主持每週兩次的開發者直播節目“Fritz and Friends”,在節目中他會與觀眾一起探討技術並編寫程式碼。 Jeff 也為包括 Microsoft Build、Microsoft Ignite、.NET Conf 和 Microsoft MVP Summit 在內的微軟大型開發者活動撰寫研討會、簡報並策劃內容。
準備好開始了嗎?
Nuget 下載 17,012,929 | 版本: 2025.12 剛剛發布