A Developer's Guide to Digitally Signing PDFs with C#
PDFドキュメントに署名を追加することは、多くのアプリケーションにおいて一般的な要件ですが、「署名」はさまざまな意味を持つことがあります。 一部の人にとっては、セキュリティ証明書を使用して改ざん防止のデジタル署名を適用することを意味します。 他の人にとっては、書面や手書きの署名画像をドキュメントにスタンプしたり、ユーザーが電子的に署名するためのインタラクティブなフォームフィールドを追加したりすることを意味するかもしれません。
このガイドは、IronPDF for .NETライブラリを使用してこれらのタスクすべてを達成するためのC#開発者向けの包括的なウォークスルーを提供します。 私たちは、X509Certificate2デジタル署名の適用からグラフィカル署名のスタンプ、インタラクティブ署名フィールドの作成まで、PDFドキュメントが本物で、安全で、プロフェッショナルであることを保証するためにすべてをカバーします。
クイックスタート:IronPDFを使用して簡単にPDFをデジタル署名する
IronPDFを使用してPDFドキュメントにデジタル署名するためのシンプルで直感的なプロセスで迅速に開始できます。 .pfx証明書を使用してPDFファイルを認証し署名し、ドキュメントの整合性と信憑性を保証する方法を示しています。 これらの手順に従って、アプリケーションにデジタル署名をシームレスに統合し、ユーザーにセキュリティと信頼性のあるPDF機能を提供してください。
Get started making PDFs with NuGet now:
Install IronPDF with NuGet Package Manager
Copy and run this code snippet.
new IronPdf.Signing.PdfSignature("certificate.pfx", "password").SignPdfFile("input.pdf");Deploy to test on your live environment
最小ワークフロー(5ステップ)
- .NET用のIronPDFライブラリをインストールします。
- X509Certificate2オブジェクトを使用してデジタル署名を適用します。
- デジタル署名を表す視覚的な画像を追加します。
- グラフィカルまたは手書きの署名をPDFファイルにスタンプします。
- 電子署名用のインタラクティブな署名フォームフィールドを追加します。
証明書を使用してPDFにデジタル署名を適用するにはどうすればよいですか?
.pfxや.p12などのデジタル証明書ファイルを使用してPDFドキュメントにデジタル署名を適用し、ドキュメントの真実性と整合性を保証できます。 このプロセスは、署名されてからドキュメントが変更されていないことを保証します。
IronPDFはこの目的のためのシンプルなAPIを提供し、デジタル署名を適用するための複数の方法をサポートしています。 この機能の核となるのはPdfSignatureクラスであり、証明書と署名に関連するすべてのメタデータを含んでいます。
| 署名方法 | 説明 |
|---|---|
Sign | PdfSignatureオブジェクトでPDFに署名します。 |
SignWithFile | ディスク上に存在するデジタル署名証明書ファイル(.pfxまたは.p12)を使用してPDFに署名します。 |
SignWithStore | コンピュータの証明書ストアからデジタル署名を取得し、そのthumbprint IDで識別してPDFに署名します。 |
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")
上記のコードはまずシンプルなPDFを生成します。 次に、.pfx証明書ファイルをX509Certificate2オブジェクトに読み込みます。 このオブジェクトはデジタルアイデンティティを表しており、PdfSignatureコンストラクターに渡されます。 最後に、pdf.Signメソッドがこの署名をドキュメントに適用し、保存します。 For more information on the X509Certificate2 class, you can refer to the official Microsoft documentation.
デジタル署名に詳細を追加する
デジタル署名には証明書だけでなく、署名に関するコンテキストを提供するリッチなメタデータを埋め込むことができます。 これには署名場所、理由、連絡先情報、信頼できる機関からのセキュアなタイムスタンプが含まれます。 これらの詳細を追加することで、ドキュメントの監査証跡が改善され、検証者に貴重な情報が提供されます。
IronPDFはまた、最新のSHA256およびSHA512ハッシュアルゴリズムを使用したタイムスタンピングサーバーもサポートしています。 一部の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");
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")
緑のチェックマークを得るには、証明書をビューアの信頼されたIDに追加する必要があります。 ## デジタル署名に視覚的表現を追加するにはどうすればよいですか?
デジタル署名はPDFに暗号的に埋め込まれていますが、ページに視覚的表現を持つことはしばしば有益です。
これは企業のロゴ、手書きの署名画像、その他のグラフィックである可能性があります。 IronPDFはPdfSignatureオブジェクトに画像を追加することを容易にします。 ファイルやストリームから画像を読み込み、PDFの任意のページに正確に配置できます。
サポートされている画像フォーマットにはPNG、JPEG、GIF、BMP、TIFF、WebPがあります。 このコードは、デジタル署名に視覚的コンポーネントを追加するための3つの同等の方法を示しています。
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">
ディスク上やメモリ上に画像を持っている場合でも、簡単にそれをPDFにスタンプとして押すことができます。 これにより、不可視の暗号的セキュリティと可視的なドキュメント承認との間のギャップが埋まります。 ## 署名後にドキュメントの権限を制御するにはどうすればよいですか?
ドキュメントに署名する際に、その後許可される変更の有無を指定したい場合があります。
たとえば、ドキュメントを完全にロックしたり、ユーザーがフォームフィールドに入力することのみを許可したりするかもしれません。 IronPDFはSignaturePermissions列挙型を使用してこれらの権限を設定することができます。 署名権限を設定することは、ドキュメントのライフサイクルを管理するのに不可欠です。
それにより、署名が適用された後のドキュメントの整合性があなたのルールに従って維持されます。 ユーザーが許可されていないアクションを実行した場合、署名は無効になります。
SignaturePermissionsメンバー | 定義 |
|---|---|
NoChangesAllowed | どのような変更も許可されていません。ドキュメントは実質的にロックされます。 |
FormFillingAllowed | 既存のフォームフィールドの記入と署名のみが許可されます。 |
AnnotationsAndFormFillingAllowed | フォームの記入、署名、注釈の作成または変更が許可されます。 |
SignaturePermissionsメンバー | 定義 |
|---|---|
NoChangesAllowed | どのような変更も許可されていません。ドキュメントは実質的にロックされます。 |
FormFillingAllowed | 既存のフォームフィールドの記入と署名のみが許可されます。 |
AnnotationsAndFormFillingAllowed | フォームの記入、署名、注釈の作成または変更が許可されます。 |
特定のPDFリビジョンの保存と署名
PDFはバージョン管理システムのように、変更履歴を保存できます。
これはインクリメンタル保存と呼ばれます。 PDFに署名する際、署名はドキュメントの特定のリビジョンに適用されます。 これは、ドキュメントが複数の承認ステージを経るワークフローにおいて重要です。 次の例では、PDFをロードし、編集を加え、現在のリビジョンに署名して、その後の変更としてフォーム入力のみを許可します。
SaveAsRevisionを使用して、ファイルを保存する前に、現在の状態をドキュメントの履歴にコミットします。 インクリメンタル保存を理解することは、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");
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")
シンプルなビューアは最新バージョンしか表示しないかもしれませんが、Adobe Acrobatのようなツールはリビジョン履歴全体を開示し、どのバージョンが誰によって署名され、署名間でどのような変更が行われたかを示します。 IronPDFはこのプロセスに完全なプログラム制御を提供します。 高セキュリティとコンプライアンスを必要とする複雑なドキュメントワークフローを管理する企業向けに、包括的なソリューションが必要な場合があります。
Iron Softwareは
PDFドキュメントには、さまざまなリビジョンにまたがって複数の署名を適用することができます。
IronPDFはこの履歴を効果的に管理するためのツールを提供します。 - 以前のリビジョンへのロールバック: GetRevisionメソッドを使用して、ドキュメントを以前の状態に戻すことができます。
これにより、そのリビジョン以降の変更や署名はすべて破棄されます。 - すべての署名を検証する: VerifySignaturesメソッドは、ドキュメントのすべてのリビジョンにわたるすべての署名の有効性をチェックします。
すべての署名が有効であり、許可されていない変更がない場合にのみtrueを返します。 - 署名を削除する: RemoveSignaturesメソッドは、ドキュメントのすべてのリビジョンからすべてのデジタル署名を削除し、クリーンな未署名のバージョンを作成します。
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.
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")
場合によっては、デジタル署名の暗号セキュリティを必要とせず、シンプルに視覚的な電子署名、例えばスキャンした手書きの署名を適用したいことがあります。
これはしばしばスタンピングと呼ばれます。 IronPDFは、WatermarkまたはStamp機能を使用してこれを行うことができます。 サンプルのインボイスPDFと手書きの署名の.png画像から始めましょう。
_署名をスタンプする前の元のインボイスPDF。
_署名をスタンプする前の元のインボイスPDF。
ここでは適用する署名画像を示します:

_サンプルの手書き署名画像。
以下のコードは、この画像を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")
コードを実行した後、署名画像がドキュメントにスタンプされ、視覚的に署名されたインボイスが作成されます。
_右下隅に手書き署名画像のスタンプされた最終PDF。
_右下隅に手書き署名画像のスタンプされた最終PDF。
PDFにインタラクティブ署名フィールドを追加するにはどうすればよいですか?
エンドユーザーがAdobe AcrobatのようなPDFビューワーで署名する必要があるドキュメントには、インタラクティブな署名フォームフィールドを追加できます。
これにより、ユーザーに独自のデジタル署名を適用させるよう促す、空でクリック可能な領域を作成します。 SignatureFormField を作成し、PDF のフォームコレクションに追加できます。
ページ上の位置とサイズを正確に制御できます。 ユーザーがこのPDFを開いたとき、クリック可能なフィールドが表示され、ユーザー独自のデジタルIDを使用して署名プロセスを完了できます。
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")
インタラクティブなフォームの作成と管理についての詳細は、PDFフォーム作成に関するハウツーガイドで学ぶことができます。 
_プログラムでPDFドキュメントに追加された未署名のインタラクティブ署名フィールド。
検証済み署名から署名者名を取得するにはどうすればよいですか?
署名を行った証明書所有者の共通名を取得するには、VerifiedSignatureクラスを使用してSignerNameプロパティにアクセスできます。
これを達成する方法を示すコードスニペットを以下に示します。 署名済みのPDFファイルをインポートした後、GetVerifiedSignatures メソッドを利用して、レポート内の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
このガイドでは、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.
次に何ができるのかを見てみましょうか? こちらのチュートリアルページをご覧ください: PDFの署名とセキュリティの確保
よくある質問
C#で証明書ファイルを使用してPDFにデジタル署名を適用するにはどうすれば良いですか?
C#で証明書ファイルを使用してPDFにデジタル署名を適用するためには、IronPDFを利用することができます。証明書をX509Certificate2オブジェクトに読み込み、IronPDFのPdfSignatureクラスを使用してドキュメントにSignメソッドで適用します。
PDF文書にデジタル署名を使用することの利点は何ですか?
デジタル署名は、PDF文書の認証と整合性を提供します。IronPDFを使用すると、文書が認証済みのソースによって署名され、署名が適用されてから変更されていないことを確認できます。
C#でPDFに手書きの署名を追加するにはどうすれば良いですか?
IronPDFを使用すると、PDFに手書きの署名をスタンプすることで追加することができます。ApplyStampメソッドをHtmlStampと共に使用し、画像ファイルを指定してこれを実現します。
PDFにインタラクティブな署名フィールドを追加するプロセスは何ですか?
PDFにインタラクティブな署名フィールドを追加するには、希望する名前、ページ、および場所を含むSignatureFormFieldオブジェクトを作成します。このフィールドをPDF文書のFormコレクションにIronPDFを使用して追加し、文書を保存します。
署名されたPDFに対して権限を制御することは可能ですか?
はい、IronPDFでPDFに署名するとき、SignaturePermissionsを指定して、文書が署名された後に許可される変更を制御できます。オプションには、NoChangesAllowed、FormFillingAllowed、およびAnnotationsAndFormFillingAllowedが含まれます。
PDFのデジタル署名の正当性をどのように検証するのですか?
IronPDFは、PDF内のすべての署名の有効性を確認するVerifySignaturesメソッドを提供しています。すべての署名が真正で改ざんされていないかどうかを示すブール値を返します。
PDFでのインクリメンタル保存とは何ですか、またそれはなぜ役立つのでしょうか?
PDFでのインクリメンタル保存は、複数の文書バージョンを1つのファイルに保存できるようにします。この機能は、変更履歴を維持し、各デジタル署名が署名時に正しい文書バージョンに対応することを保証するために役立ちます。
PDFのデジタル署名にメタデータを追加するにはどうしたら良いですか?
IronPDFを使用すると、署名の理由、場所、タイムスタンプなどのメタデータでデジタル署名を充実させることができます。PdfSignatureオブジェクトを作成する際に設定し、署名プロセスの詳細な記録を可能にします。
IronPDFのデジタル署名機能を.NET 10アプリケーションで使用できますか?
はい。IronPDFは.NET 10を完全にサポートしているため、この記事で示されている同じX509Certificate2ベースのデジタル署名ワークフローが.NET 10のコンソール、ウェブ、サービスアプリケーションで機能します。単に.NET 10プロジェクトを作成し、NuGetから最新のIronPdfパッケージをインストールし、署名コードを再利用して、目に見えないや見える署名、署名画像、および署名フォームフィールドを適用してください。

