Class PdfSignature
Represents a digital signature used for signing a PDF document.
Inheritance
Namespace: Syncfusion.Pdf.Security
Assembly: Syncfusion.Pdf.NET.dll
Syntax
public class PdfSignature : Object
Remarks
This API is not supported in WinRT, Windows Phone, Xamarin, Universal Windows Platform and Silverlight.
Examples
// Creates a new document
PdfDocument doc = new PdfDocument();
//Creates a new page and adds it as the last page of the document
PdfPage page = doc.Pages.Add();
PdfCertificate pdfCert = new PdfCertificate("Pdf.pfx", "123");
PdfSignature signature = new PdfSignature(doc, page, pdfCert, "Signature");
signature.Bounds = new RectangleF(new PointF(5, 5),new SizeF(100,200));
doc.Save("SignedPdfSample.pdf");
doc.Close(true);
' Creates a new document
Dim doc As PdfDocument = New PdfDocument()
' Create a page
Dim page As PdfPage = doc.Pages.Add()
Dim pdfCert As PdfCertificate = New PdfCertificate("Pdf.pfx", "123")
Dim signature As PdfSignature = New PdfSignature(doc, page, pdfCert, "Signature")
signature.Bounds = New RectangleF(New PointF(5, 5),New SizeF(100,200))
doc.Save("SignedPdfSample.pdf")
doc.Close(True)
Constructors
PdfSignature()
Initializes a new instance of the PdfSignature class.
Declaration
public PdfSignature()
Remarks
This constructor is not supported in WinRT, Windows Phone, Xamarin, Universal Windows Platform and Silverlight.
PdfSignature(PdfDocumentBase, PdfPageBase, PdfCertificate, String)
Initializes a new instance of the PdfSignature class with the PDF document, page, certificate and the signature name.
Declaration
public PdfSignature(PdfDocumentBase document, PdfPageBase page, PdfCertificate certificate, string signatureName)
Parameters
Type | Name | Description |
---|---|---|
PdfDocumentBase | document | The document, which has the page. |
PdfPageBase | page | The page. |
PdfCertificate | certificate | The certificate. |
System.String | signatureName | The name of the signature. |
Remarks
This constructor is not supported in WinRT, Windows Phone, Xamarin, Universal Windows Platform and Silverlight.
Examples
// Creates a new document
PdfDocument doc = new PdfDocument();
//Creates a new page and adds it as the last page of the document
PdfPage page = doc.Pages.Add();
PdfCertificate pdfCert = new PdfCertificate("Pdf.pfx", "123");
PdfSignature signature = new PdfSignature(doc, page, pdfCert, "Signature");
signature.Bounds = new RectangleF(new PointF(5, 5),new SizeF(100,200));
doc.Save("SignedPdfSample.pdf");
' Creates a new document
Dim doc As PdfDocument = New PdfDocument()
' Create a page
Dim page As PdfPage = doc.Pages.Add()
Dim pdfCert As PdfCertificate = New PdfCertificate("Pdf.pfx", "123")
Dim signature As PdfSignature = New PdfSignature(doc, page, pdfCert, "Signature")
signature.Bounds = New RectangleF(New PointF(5, 5),New SizeF(100,200))
doc.Save("SignedPdfSample.pdf")
See Also
PdfSignature(PdfDocumentBase, PdfPageBase, PdfCertificate, String, PdfLoadedSignatureField)
Initializes a new instance of the PdfSignature class with the PDF document, page, certificate , signature name and the signature field.
Declaration
public PdfSignature(PdfDocumentBase document, PdfPageBase page, PdfCertificate certificate, string signatureName, PdfLoadedSignatureField loadedField)
Parameters
Type | Name | Description |
---|---|---|
PdfDocumentBase | document | The loaded document, which has the page. |
PdfPageBase | page | The page. |
PdfCertificate | certificate | The certificate. |
System.String | signatureName | The name of the signature. |
PdfLoadedSignatureField | loadedField | The name of the loaded signature field |
Remarks
This constructor is not supported in WinRT, Windows Phone, Xamarin, Universal Windows Platform and Silverlight.
Examples
// Creates a new document
PdfLoadedDocument doc = new PdfLoadedDocument();
//Creates a new page and adds it as the last page of the document
PdfPage page = doc.Pages.Add();
PdfCertificate pdfCert = new PdfCertificate("Pdf.pfx", "123");
PdfLoadedSignatureField signatureField = loadedDocument.Form.Fields["Signature"] as PdfLoadedSignatureField;
PdfSignature signature = new PdfSignature(doc, page, pdfCert, "Signature",signatureField);
doc.Save("SignedPdfSample.pdf");
' Creates a new document
Dim doc As PdfDocument = New PdfDocument()
' Create a page
Dim page As PdfPage = doc.Pages.Add()
Dim pdfCert As PdfCertificate = New PdfCertificate("Pdf.pfx", "123")
Dim signatureField as PdfLoadedSignatureField = TryCast(loadedDocument.Form.Fields["Signature"],PdfLoadedSignature)
Dim signature As PdfSignature = New PdfSignature(doc, page, pdfCert, "Signature",signatureField)
doc.Save("SignedPdfSample.pdf")
See Also
PdfSignature(PdfLoadedPage, String)
Initializes a new instance of the PdfSignature class with the Loaded page and the signature name.
Declaration
public PdfSignature(PdfLoadedPage page, string signatureName)
Parameters
Type | Name | Description |
---|---|---|
PdfLoadedPage | page | The current pdf loaded page where signature will be added. |
System.String | signatureName | Name of the signature. |
Remarks
This constructor is not supported in WinRT, Windows Phone, Xamarin, Universal Windows Platform and Silverlight.
Examples
Load an existing document
PdfLoadedDocument doc = new PdfLoadedDocument("SourceForm.pdf");
Gets the signature field
PdfLoadedSignatureField signatureField = doc.Form.Fields[0] as PdfLoadedSignatureField;
PdfSignature signature = new PdfSignature(page1, "Timestamp2");
signatureField.Signature = signature;
doc.Save("LoadedForm.pdf");
doc.Close(true);
PdfSignature(PdfPage, PdfCertificate, String)
Initializes a new instance of the PdfSignature class with the page, certificate and the signature name.
Declaration
public PdfSignature(PdfPage page, PdfCertificate cert, string signatureName)
Parameters
Type | Name | Description |
---|---|---|
PdfPage | page | The current pdf page where signature will be replaced. |
PdfCertificate | cert | The pdf certificate. |
System.String | signatureName | Name of the signature. |
Remarks
This constructor is not supported in WinRT, Windows Phone, Xamarin, Universal Windows Platform and Silverlight.
Examples
// Creates a new document
PdfDocument doc = new PdfDocument();
//Creates a new page and adds it as the last page of the document
PdfPage page = doc.Pages.Add();
PdfCertificate pdfCert = new PdfCertificate("Pdf.pfx", "123");
PdfSignature signature = new PdfSignature(page, pdfCert, "Signature");
signature.Bounds = new RectangleF(new PointF(5, 5),new SizeF(100,200));
doc.Save("SignedPdfSample.pdf");
' Creates a new document
Dim doc As PdfDocument = New PdfDocument()
' Create a page
Dim page As PdfPage = doc.Pages.Add()
Dim pdfCert As PdfCertificate = New PdfCertificate("Pdf.pfx", "123")
Dim signature As PdfSignature = New PdfSignature(page, pdfCert, "Signature")
signature.Bounds = New RectangleF(New PointF(5, 5),New SizeF(100,200))
doc.Save("SignedPdfSample.pdf")
See Also
PdfSignature(PdfPage, String)
Initializes a new instance of the PdfSignature class with the page, certificate and the signature name.
Declaration
public PdfSignature(PdfPage page, string signatureName)
Parameters
Type | Name | Description |
---|---|---|
PdfPage | page | The current pdf page where signature will be replaced. |
System.String | signatureName | Name of the signature. |
Remarks
This constructor is not supported in WinRT, Windows Phone, Xamarin, Universal Windows Platform and Silverlight.
Examples
// Creates a new document
PdfDocument doc = new PdfDocument();
//Creates a new page and adds it as the last page of the document
PdfPage page = doc.Pages.Add();
PdfCertificate pdfCert = new PdfCertificate("Pdf.pfx", "123");
PdfSignature signature = new PdfSignature(page, "Signature");
signature.Bounds = new RectangleF(new PointF(5, 5),new SizeF(100,200));
doc.Save("SignedPdfSample.pdf");
' Creates a new document
Dim doc As PdfDocument = New PdfDocument()
' Create a page
Dim page As PdfPage = doc.Pages.Add()
Dim pdfCert As PdfCertificate = New PdfCertificate("Pdf.pfx", "123")
Dim signature As PdfSignature = New PdfSignature(page, "Signature")
signature.Bounds = New RectangleF(New PointF(5, 5),New SizeF(100,200))
doc.Save("SignedPdfSample.pdf")
See Also
Properties
Appearance
Gets the signature Appearance.[Read-Only]
Declaration
public PdfAppearance Appearance { get; }
Property Value
Type | Description |
---|---|
PdfAppearance | A PdfAppearance object defines signature`s appearance. |
Remarks
This property is not supported in WinRT, Windows Phone, Xamarin, Universal Windows Platform and Silverlight.
Examples
// Creates a new document
PdfDocument doc = new PdfDocument();
//Creates a new page and adds it as the last page of the document
PdfPage page = doc.Pages.Add();
PdfCertificate pdfCert = new PdfCertificate("Pdf.pfx", "123");
PdfSignature signature = new PdfSignature(doc, page, pdfCert, "Signature");
PdfAppearance appearance = signature.Appearence;
signature.Bounds = new RectangleF(new PointF(5, 5),new SizeF(100,200));
doc.Save("SignedPdfSample.pdf");
doc.Close(true);
' Creates a new document
Dim doc As PdfDocument = New PdfDocument()
' Create a page
Dim page As PdfPage = doc.Pages.Add()
Dim pdfCert As PdfCertificate = New PdfCertificate("Pdf.pfx", "123")
Dim signature As PdfSignature = New PdfSignature(doc, page, pdfCert, "Signature")
Dim appearance As PdfAppearance = signature.Appearence
signature.Bounds = New RectangleF(New PointF(5, 5),New SizeF(100,200))
doc.Save("SignedPdfSample.pdf")
doc.Close(True)
See Also
Appearence
Gets the signature Appearance.[Read-Only]
Declaration
public PdfAppearance Appearence { get; }
Property Value
Type | Description |
---|---|
PdfAppearance | A PdfAppearance object defines signature`s appearance. |
Remarks
This property is not supported in WinRT, Windows Phone, Xamarin, Universal Windows Platform and Silverlight.
Examples
// Creates a new document
PdfDocument doc = new PdfDocument();
//Creates a new page and adds it as the last page of the document
PdfPage page = doc.Pages.Add();
PdfCertificate pdfCert = new PdfCertificate("Pdf.pfx", "123");
PdfSignature signature = new PdfSignature(doc, page, pdfCert, "Signature");
PdfAppearance appearance = signature.Appearence;
signature.Bounds = new RectangleF(new PointF(5, 5),new SizeF(100,200));
doc.Save("SignedPdfSample.pdf");
doc.Close(true);
' Creates a new document
Dim doc As PdfDocument = New PdfDocument()
' Create a page
Dim page As PdfPage = doc.Pages.Add()
Dim pdfCert As PdfCertificate = New PdfCertificate("Pdf.pfx", "123")
Dim signature As PdfSignature = New PdfSignature(doc, page, pdfCert, "Signature")
Dim appearance As PdfAppearance = signature.Appearence
signature.Bounds = New RectangleF(New PointF(5, 5),New SizeF(100,200))
doc.Save("SignedPdfSample.pdf")
doc.Close(True)
See Also
Bounds
Gets or sets bounds of the signature.
Declaration
public RectangleF Bounds { get; set; }
Property Value
Type |
---|
RectangleF |
Remarks
This property is not supported in WinRT, Windows Phone, Xamarin, Universal Windows Platform and Silverlight.
Examples
// Creates a new document
PdfDocument doc = new PdfDocument();
//Creates a new page and adds it as the last page of the document
PdfPage page = doc.Pages.Add();
PdfCertificate pdfCert = new PdfCertificate("Pdf.pfx", "123");
PdfSignature signature = new PdfSignature(doc, page, pdfCert, "Signature");
signature.Location = new PointF(100, 200);
signature.Bounds = new RectangleF(new PointF(5, 5),new SizeF(100,200));
doc.Save("SignedPdfSample.pdf");
doc.Close(true);
' Creates a new document
Dim doc As PdfDocument = New PdfDocument()
' Create a page
Dim page As PdfPage = doc.Pages.Add()
Dim pdfCert As PdfCertificate = New PdfCertificate("Pdf.pfx", "123")
Dim signature As PdfSignature = New PdfSignature(doc, page, pdfCert, "Signature")
signature.Location = New PointF(100, 200)
signature.Bounds = New RectangleF(New PointF(5, 5),New SizeF(100,200))
doc.Save("SignedPdfSample.pdf")
doc.Close(True)
See Also
Certificate
Gets or sets the signing certificate.
Declaration
public PdfCertificate Certificate { get; set; }
Property Value
Type |
---|
PdfCertificate |
Remarks
This property is not supported in WinRT, Windows Phone, Xamarin, Universal Windows Platform and Silverlight.
Examples
// Creates a new document
PdfDocument doc = new PdfDocument();
//Creates a new page and adds it as the last page of the document
PdfPage page = doc.Pages.Add();
PdfCertificate pdfCert = new PdfCertificate("Pdf.pfx", "123");
PdfSignature signature = new PdfSignature(doc, page, pdfCert, "Signature");
signature.ContactInfo = "Syncfusion";
signature.Bounds = new RectangleF(new PointF(5, 5),new SizeF(100,200));
doc.Save("SignedPdfSample.pdf");
doc.Close(true);
' Creates a new document
Dim doc As PdfDocument = New PdfDocument()
' Create a page
Dim page As PdfPage = doc.Pages.Add()
Dim pdfCert As PdfCertificate = New PdfCertificate("Pdf.pfx", "123")
Dim signature As PdfSignature = New PdfSignature(doc, page, pdfCert, "Signature")
signature.ContactInfo = "Syncfusion"
signature.Bounds = New RectangleF(New PointF(5, 5),New SizeF(100,200))
doc.Save("SignedPdfSample.pdf")
doc.Close(True)
See Also
Certificated
Gets or sets a value indicating certificate document or not. NOTE: Works only with Adobe Reader 7.0.8 or higher.
Declaration
public bool Certificated { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean | certificate document if true. |
Remarks
This property is not supported in WinRT, Windows Phone, Xamarin, Universal Windows Platform and Silverlight.
Examples
// Creates a new document
PdfDocument doc = new PdfDocument();
//Creates a new page and adds it as the last page of the document
PdfPage page = doc.Pages.Add();
PdfCertificate pdfCert = new PdfCertificate("Pdf.pfx", "123");
PdfSignature signature = new PdfSignature(doc, page, pdfCert, "Signature");
signature.Certificated = true;
signature.Bounds = new RectangleF(new PointF(5, 5),new SizeF(100,200));
doc.Save("SignedPdfSample.pdf");
doc.Close(true);
' Creates a new document
Dim doc As PdfDocument = New PdfDocument()
' Create a page
Dim page As PdfPage = doc.Pages.Add()
Dim pdfCert As PdfCertificate = New PdfCertificate("Pdf.pfx", "123")
Dim signature As PdfSignature = New PdfSignature(doc, page, pdfCert, "Signature")
signature.Certificated = True
signature.Bounds = New RectangleF(New PointF(5, 5),New SizeF(100,200))
doc.Save("SignedPdfSample.pdf")
doc.Close(True)
See Also
ContactInfo
Gets or sets information provided by the signer to enable a recipient to contact the signer to verify the signature; for example, a phone number.
Declaration
public string ContactInfo { get; set; }
Property Value
Type |
---|
System.String |
Remarks
This property is not supported in WinRT, Windows Phone, Xamarin, Universal Windows Platform and Silverlight.
Examples
// Creates a new document
PdfDocument doc = new PdfDocument();
//Creates a new page and adds it as the last page of the document
PdfPage page = doc.Pages.Add();
PdfCertificate pdfCert = new PdfCertificate("Pdf.pfx", "123");
PdfSignature signature = new PdfSignature(doc, page, pdfCert, "Signature");
signature.ContactInfo = "Syncfusion";
signature.Bounds = new RectangleF(new PointF(5, 5),new SizeF(100,200));
doc.Save("SignedPdfSample.pdf");
doc.Close(true);
' Creates a new document
Dim doc As PdfDocument = New PdfDocument()
' Create a page
Dim page As PdfPage = doc.Pages.Add()
Dim pdfCert As PdfCertificate = New PdfCertificate("Pdf.pfx", "123")
Dim signature As PdfSignature = New PdfSignature(doc, page, pdfCert, "Signature")
signature.ContactInfo = "Syncfusion"
signature.Bounds = New RectangleF(New PointF(5, 5),New SizeF(100,200))
doc.Save("SignedPdfSample.pdf")
doc.Close(True)
See Also
DocumentPermissions
Gets or sets the permission for certificated document.
Declaration
public PdfCertificationFlags DocumentPermissions { get; set; }
Property Value
Type | Description |
---|---|
PdfCertificationFlags | The document permission. |
Remarks
This property is not supported in WinRT, Windows Phone, Xamarin, Universal Windows Platform and Silverlight.
Examples
// Creates a new document
PdfDocument doc = new PdfDocument();
//Creates a new page and adds it as the last page of the document
PdfPage page = doc.Pages.Add();
PdfCertificate pdfCert = new PdfCertificate("Pdf.pfx", "123");
PdfSignature signature = new PdfSignature(doc, page, pdfCert, "Signature");
signature.DocumentPermissions = PdfCertificationFlags.AllowComments;
signature.Bounds = new RectangleF(new PointF(5, 5),new SizeF(100,200));
doc.Save("SignedPdfSample.pdf");
doc.Close(true);
' Creates a new document
Dim doc As PdfDocument = New PdfDocument()
' Create a page
Dim page As PdfPage = doc.Pages.Add()
Dim pdfCert As PdfCertificate = New PdfCertificate("Pdf.pfx", "123")
Dim signature As PdfSignature = New PdfSignature(doc, page, pdfCert, "Signature")
signature.DocumentPermissions = PdfCertificationFlags.AllowComments
signature.Bounds = New RectangleF(New PointF(5, 5),New SizeF(100,200))
doc.Save("SignedPdfSample.pdf")
doc.Close(True)
See Also
EnableLtv
Get or Set LTV to signed document.
Declaration
public bool EnableLtv { get; set; }
Property Value
Type |
---|
System.Boolean |
EnableValidationAppearance
Gets or sets the signature validation appearance
Declaration
public bool EnableValidationAppearance { get; set; }
Property Value
Type |
---|
System.Boolean |
Examples
// Creates a new document
PdfDocument document = new PdfDocument();
//Its handle the rotation on signature annoatation
document.PageSettings.Rotate = PdfPageRotateAngle.RotateAngle90;
PdfPageBase page = document.Pages.Add();
PdfCertificate pdfCert = new PdfCertificate(@"PDF.pfx", "syncfusion");
PdfSignature signature = new PdfSignature(document, page, pdfCert, "Signature");
signature.Bounds = new Rectangle(10, 20, 400, 200);
//set the signature validation appearance is true to update Adobe signature validation during runtime
signature.EnableValidationAppearance = true;
document.Save("Output.pdf");
document.Close();
///
' Creates a new document
Dim document As New PdfDocument()
'Creates a new page and adds it as the last page of the document
Dim page As PdfPage = document.Pages.Add()
'Load the x509 certificate.
Dim cert As New X509Certificate2("certificate.pfx", "password")
'Find by subject.
Dim pdfCert As New PdfCertificate(cert)
'Creates a signature.
Dim signature As New PdfSignature(document, page, pdfCert, "Signature")
signature.Bounds = New RectangleF(New PointF(0, 0), New SizeF(100, 100))
signature.ContactInfo = "johndoe@owned.us"
signature.LocationInfo = "Honolulu, Hawaii"
signature.Reason = "I am author of this document."
'set the signature validation appearance is true to update Adobe signature validation during runtime
signature.EnableValidationAppearance = true;
document.Save("output.pdf")
'Close the document.
document.Close(True)
EstimatedSignatureSize
Sets the estimated size of the signature. The estimated size is the size that will be reserved in the PDF document before digitally signing it. This size corresponds only to the Contents field of the signature field. The range between 0 to 536,870,911
Declaration
public uint EstimatedSignatureSize { set; }
Property Value
Type |
---|
System.UInt32 |
Examples
// Creates a new document
PdfDocument document = new PdfDocument();
// Add a new page
PdfPageBase page = document.Pages.Add();
// Create a PDF certificate
PdfCertificate pdfCert = new PdfCertificate(@"PDF.pfx", "syncfusion");
// Add a new signature to the PDF page
PdfSignature signature = new PdfSignature(document, page, pdfCert, "Signature");
signature.Bounds = new Rectangle(10, 20, 400, 200);
// Set the estimated signature size
signature.EstimatedSignatureSize = 20000;
// Save and close the document
document.Save("Output.pdf");
document.Close(True);
///
' Creates a new document
Dim document As New PdfDocument()
'Creates a new page and adds it as the last page of the document
Dim page As PdfPageBase = document.Pages.Add()
'Create a PDF certificate
Dim pdfCert As New PdfCertificate(@"PDF.pfx", "syncfusion")
'Add a new signature to the PDF page
Dim signature As New PdfSignature(document, page, pdfCert, "Signature")
signature.Bounds = new Rectangle(10, 20, 400, 200)
'Set the estimated signature size
signature.EstimatedSignatureSize = 20000
'Save and close the document
document.Save("Output.pdf")
'Close the document.
document.Close(True)
IsLocked
Gets or sets a value indicating whether to lock the signature or not.
Declaration
public bool IsLocked { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean | lock signature if true. |
Remarks
This property is not applicable for existing signed signature fields.
Examples
// Creates a new document
PdfDocument doc = new PdfDocument();
//Creates a new page and adds it as the last page of the document
PdfPage page = doc.Pages.Add();
PdfCertificate pdfCert = new PdfCertificate("Pdf.pfx", "123");
PdfSignature signature = new PdfSignature(doc, page, pdfCert, "Signature");
signature.IsLocked = true;
signature.Bounds = new RectangleF(new PointF(5, 5),new SizeF(100,200));
doc.Save("SignedPdfSample.pdf");
doc.Close(true);
' Creates a new document
Dim doc As PdfDocument = New PdfDocument()
' Create a page
Dim page As PdfPage = doc.Pages.Add()
Dim pdfCert As PdfCertificate = New PdfCertificate("Pdf.pfx", "123")
Dim signature As PdfSignature = New PdfSignature(doc, page, pdfCert, "Signature")
signature.IsLocked = True
signature.Bounds = New RectangleF(New PointF(5, 5),New SizeF(100,200))
doc.Save("SignedPdfSample.pdf")
doc.Close(True)
See Also
Location
Gets or sets signature location on the PDF page.
Declaration
public PointF Location { get; set; }
Property Value
Type |
---|
PointF |
Remarks
This porperty is not supported in WinRT, Windows Phone, Xamarin, Universal Windows Platform and Silverlight.
Examples
// Creates a new document
PdfDocument doc = new PdfDocument();
//Creates a new page and adds it as the last page of the document
PdfPage page = doc.Pages.Add();
PdfCertificate pdfCert = new PdfCertificate("Pdf.pfx", "123");
PdfSignature signature = new PdfSignature(doc, page, pdfCert, "Signature");
signature.Location = new PointF(100, 200);
signature.Bounds = new RectangleF(new PointF(5, 5),new SizeF(100,200));
doc.Save("SignedPdfSample.pdf");
doc.Close(true);
' Creates a new document
Dim doc As PdfDocument = New PdfDocument()
' Create a page
Dim page As PdfPage = doc.Pages.Add()
Dim pdfCert As PdfCertificate = New PdfCertificate("Pdf.pfx", "123")
Dim signature As PdfSignature = New PdfSignature(doc, page, pdfCert, "Signature")
signature.Location = New PointF(100, 200)
signature.Bounds = New RectangleF(New PointF(5, 5),New SizeF(100,200))
doc.Save("SignedPdfSample.pdf")
doc.Close(True)
See Also
LocationInfo
Gets or sets the physical location of the signing.
Declaration
public string LocationInfo { get; set; }
Property Value
Type |
---|
System.String |
Remarks
This property is not supported in WinRT, Windows Phone, Xamarin, Universal Windows Platform and Silverlight.
Examples
// Creates a new document
PdfDocument doc = new PdfDocument();
//Creates a new page and adds it as the last page of the document
PdfPage page = doc.Pages.Add();
PdfCertificate pdfCert = new PdfCertificate("Pdf.pfx", "123");
PdfSignature signature = new PdfSignature(doc, page, pdfCert, "Signature");
signature.LocationInfo = "US";
signature.Bounds = new RectangleF(new PointF(5, 5),new SizeF(100,200));
doc.Save("SignedPdfSample.pdf");
doc.Close(true);
' Creates a new document
Dim doc As PdfDocument = New PdfDocument()
' Create a page
Dim page As PdfPage = doc.Pages.Add()
Dim pdfCert As PdfCertificate = New PdfCertificate("Pdf.pfx", "123")
Dim signature As PdfSignature = New PdfSignature(doc, page, pdfCert, "Signature")
signature.LocationInfo = "US"
signature.Bounds = New RectangleF(New PointF(5, 5),New SizeF(100,200))
doc.Save("SignedPdfSample.pdf")
doc.Close(True)
See Also
Reason
Gets or sets reason of signing.
Declaration
public string Reason { get; set; }
Property Value
Type |
---|
System.String |
Remarks
This property is not supported in WinRT, Windows Phone, Xamarin, Universal Windows Platform and Silverlight.
Examples
// Creates a new document
PdfDocument doc = new PdfDocument();
//Creates a new page and adds it as the last page of the document
PdfPage page = doc.Pages.Add();
PdfCertificate pdfCert = new PdfCertificate("Pdf.pfx", "123");
PdfSignature signature = new PdfSignature(doc, page, pdfCert, "Signature");
signature.Reason = "PDF is signed";
signature.Bounds = new RectangleF(new PointF(5, 5),new SizeF(100,200));
doc.Save("SignedPdfSample.pdf");
doc.Close(true);
' Creates a new document
Dim doc As PdfDocument = New PdfDocument()
' Create a page
Dim page As PdfPage = doc.Pages.Add()
Dim pdfCert As PdfCertificate = New PdfCertificate("Pdf.pfx", "123")
Dim signature As PdfSignature = New PdfSignature(doc, page, pdfCert, "Signature")
signature.Reason = "PDF is signed"
signature.Bounds = New RectangleF(New PointF(5, 5),New SizeF(100,200))
doc.Save("SignedPdfSample.pdf")
doc.Close(True)
See Also
Settings
Gets or sets the signature settings
Declaration
public PdfSignatureSettings Settings { get; }
Property Value
Type | Description |
---|---|
PdfSignatureSettings | A PdfSignatureSettings object defines signature`s settings. |
Examples
//Creates a new PDF document.
PdfDocument document = new PdfDocument();
//Adds a new page.
PdfPageBase page = document.Pages.Add();
PdfGraphics graphics = page.Graphics;
//Creates a certificate instance from PFX file with private key.
PdfCertificate pdfCert = new PdfCertificate(@"PDF.pfx", "syncfusion");
//Creates a digital signature.
PdfSignature signature = new PdfSignature(document, page, pdfCert, "Signature");
//Sets signature settings to customize digestion algorithm and cryptographic standrad specified
PdfSignatureSettings properties = signature.Settings;
properties.CryptographicStandard = CryptographicStandard.CADES;
properties.DigestAlgorithm = DigestAlgorithm.SHA256;
//Sets an image for signature field.
PdfBitmap signatureImage = new PdfBitmap(@"signature.jpg");
//Sets signature information
signature.Bounds = new RectangleF(new PointF(0, 0), signatureImage.PhysicalDimension);
signature.ContactInfo = "johndoe@owned.us";
signature.LocationInfo = "Honolulu, Hawaii";
signature.Reason = "I am author of this document.";
//Draws the signature image.
graphics.DrawImage(signatureImage, 0, 0);
//Saves and closes the document.
document.Save("Output.pdf");
document.Close(true);
'Creates a new PDF document.
Dim document As New PdfDocument()
'Adds a new page.
Dim page As PdfPageBase = document.Pages.Add()
Dim graphics As PdfGraphics = page.Graphics
'Creates a certificate instance from PFX file with private key.
Dim pdfCert As New PdfCertificate("PDF.pfx", "syncfusion")
'Creates a digital signature.
Dim signature As New PdfSignature(document, page, pdfCert, "Signature")
'Sets signature settings to customize digestion algorithm and cryptographic standrad specified
Dim properties As PdfSignatureSettings = signature.Settings;
properties.CryptographicStandard = CryptographicStandard.CADES;
properties.DigestAlgorithm = DigestAlgorithm.SHA256;
'Sets an image for signature field.
Dim signatureImage As New PdfBitmap("signature.jpg")
'Sets signature info.
signature.Bounds = New RectangleF(New PointF(0, 0), signatureImage.PhysicalDimension)
signature.ContactInfo = "johndoe@owned.us"
signature.LocationInfo = "Honolulu, Hawaii"
signature.Reason = "I am author of this document."
'Draws the signature image.
graphics.DrawImage(signatureImage, 0, 0)
'Saves and closes the document.
document.Save("Output.pdf")
document.Close(True)
SignedDate
Get signed Date
Declaration
public DateTime SignedDate { get; }
Property Value
Type |
---|
System.DateTime |
SignedName
Gets or sets the signed name
Declaration
public string SignedName { get; set; }
Property Value
Type |
---|
System.String |
Examples
// Creates a new document
PdfDocument document = new PdfDocument();
// Add a new page
PdfPageBase page = document.Pages.Add();
// Create a PDF certificate
PdfCertificate pdfCert = new PdfCertificate(@"PDF.pfx", "syncfusion");
// Add a new signature to the PDF page
PdfSignature signature = new PdfSignature(document, page, pdfCert, "Signature");
signature.Bounds = new Rectangle(10, 20, 400, 200);
// Set the signed name
signature.SignedName = "Syncfusion Signature";
// Save and close the document
document.Save("Output.pdf");
document.Close(True);
///
' Creates a new document
Dim document As New PdfDocument()
'Creates a new page and adds it as the last page of the document
Dim page As PdfPageBase = document.Pages.Add()
'Create a PDF certificate
Dim pdfCert As New PdfCertificate(@"PDF.pfx", "syncfusion")
'Add a new signature to the PDF page
Dim signature As New PdfSignature(document, page, pdfCert, "Signature")
signature.Bounds = new Rectangle(10, 20, 400, 200)
'Set the signed name
signature.SignedName = "Syncfusion Signature"
'Save and close the document
document.Save("Output.pdf")
'Close the document.
document.Close(True)
TimeStampServer
Gets or sets time stamping server unique resource identifier.
Declaration
public TimeStampServer TimeStampServer { get; set; }
Property Value
Type |
---|
TimeStampServer |
Remarks
This property is not supported in WinRT, Windows Phone, Xamarin, Universal Windows Platform and Silverlight.
Examples
// Creates a new document
PdfDocument document = new PdfDocument();
//Creates a new page and adds it as the last page of the document
PdfPage page = document.Pages.Add();
//Load the x509 certificate.
X509Certificate2 cert = new X509Certificate2("certificate.pfx", "password");
//Find by subject.
PdfCertificate pdfCert = new PdfCertificate(cert);
//Creates a signature.
PdfSignature signature = new PdfSignature(document, page, pdfCert, "Signature");
signature.Bounds = new RectangleF(new PointF(0, 0), new SizeF(100, 100));
signature.ContactInfo = "johndoe@owned.us";
signature.LocationInfo = "Honolulu, Hawaii";
signature.Reason = "I am author of this document.";
//Add time stamp.
signature.TimeStampServer = new TimeStampServer(new Uri("http://syncfusion.digistamp.com"), "user", "123456");
//Save the document.
document.Save("output.pdf");
//Close the document.
document.Close(true);
' Creates a new document
Dim document As New PdfDocument()
'Creates a new page and adds it as the last page of the document
Dim page As PdfPage = document.Pages.Add()
'Load the x509 certificate.
Dim cert As New X509Certificate2("certificate.pfx", "password")
'Find by subject.
Dim pdfCert As New PdfCertificate(cert)
'Creates a signature.
Dim signature As New PdfSignature(document, page, pdfCert, "Signature")
signature.Bounds = New RectangleF(New PointF(0, 0), New SizeF(100, 100))
signature.ContactInfo = "johndoe@owned.us"
signature.LocationInfo = "Honolulu, Hawaii"
signature.Reason = "I am author of this document."
'Add time stamp.
signature.TimeStampServer = New TimeStampServer(New Uri("http://syncfusion.digistamp.com"), "user", "123456")
'Save the document.
document.Save("output.pdf")
'Close the document.
document.Close(True)
Visible
Gets a value indicating whether signature visible or not.[Read-Only]
Declaration
public bool Visible { get; }
Property Value
Type |
---|
System.Boolean |
Remarks
Signature can be set as invisible when its Bounds size is set to empty. This property is not supported in WinRT, Windows Phone, Xamarin, Universal Windows Platform and Silverlight.
Examples
// Creates a new document
PdfDocument doc = new PdfDocument();
//Creates a new page and adds it as the last page of the document
PdfPage page = doc.Pages.Add();
PdfCertificate pdfCert = new PdfCertificate("Pdf.pfx", "123");
PdfSignature signature = new PdfSignature(doc, page, pdfCert, "Signature");
signature.Visible = false;
signature.Bounds = new RectangleF(new PointF(5, 5),new SizeF(100,200));
doc.Save("SignedPdfSample.pdf");
doc.Close(true);
' Creates a new document
Dim doc As PdfDocument = New PdfDocument()
' Create a page
Dim page As PdfPage = doc.Pages.Add()
Dim pdfCert As PdfCertificate = New PdfCertificate("Pdf.pfx", "123")
Dim signature As PdfSignature = New PdfSignature(doc, page, pdfCert, "Signature")
signature.Visible = False
signature.Bounds = New RectangleF(New PointF(5, 5),New SizeF(100,200))
doc.Save("SignedPdfSample.pdf")
doc.Close(True)
See Also
Methods
add_ComputeHash(PdfSignatureEventHandler)
Declaration
public void add_ComputeHash(PdfSignatureEventHandler value)
Parameters
Type | Name | Description |
---|---|---|
PdfSignatureEventHandler | value |
AddExternalSigner(IPdfExternalSigner, List<X509Certificate2>, Byte[])
Add External Signer for signature
Declaration
public void AddExternalSigner(IPdfExternalSigner signer, List<X509Certificate2> publicCertificates, byte[] Ocsp)
Parameters
Type | Name | Description |
---|---|---|
IPdfExternalSigner | signer | |
System.Collections.Generic.List<System.Security.Cryptography.X509Certificates.X509Certificate2> | publicCertificates | |
System.Byte[] | Ocsp |
CreateLongTermValidity(List<X509Certificate2>, RevocationType, Boolean)
Create long term validation of the signature.
Declaration
public void CreateLongTermValidity(List<X509Certificate2> certificates, RevocationType type, bool includePublicCertificates = false)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.List<System.Security.Cryptography.X509Certificates.X509Certificate2> | certificates | A list of X.509 certificates to process. |
RevocationType | type | The revocation type. |
System.Boolean | includePublicCertificates | A flag indicating whether the public certificates are included on the LTV. The default value is false. |
Examples
//Load the PDF document.
PdfLoadedDocument loadedDocument = new PdfLoadedDocument("input.pdf");
//Get the existing page.
PdfLoadedPage page = loadedDocument.Pages[0] as PdfLoadedPage;
//Create a new PdfSignature instance.
PdfSignature signature = new PdfSignature(loadedDocument, page, null, "Sig1");
//Create LTV with X509 public certificates.
signature.CreateLtv(certificates, RevocationType.OcspAndCrl);
//Save and close the PDF document.
loadedDocument.Save("output.pdf");
loadedDocument.Close(true);
CreateLongTermValidity(List<X509Certificate2>, Boolean)
Create long term validation of the signature.
Declaration
public void CreateLongTermValidity(List<X509Certificate2> certificates, bool includePublicCertificates = false)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.List<System.Security.Cryptography.X509Certificates.X509Certificate2> | certificates | A list of X.509 certificates to process. |
System.Boolean | includePublicCertificates | A flag indicating whether the public certificates are included on the LTV. The default value is false. |
Examples
//Load the PDF document.
PdfLoadedDocument loadedDocument = new PdfLoadedDocument("input.pdf");
//Get the existing page.
PdfLoadedPage page = loadedDocument.Pages[0] as PdfLoadedPage;
//Create a new PdfSignature instance.
PdfSignature signature = new PdfSignature(loadedDocument, page, null, "Sig1");
//Create LTV with X509 public certificates.
signature.CreateLtv(certificates);
//Save and close the PDF document.
loadedDocument.Save("output.pdf");
loadedDocument.Close(true);
remove_ComputeHash(PdfSignatureEventHandler)
Declaration
public void remove_ComputeHash(PdfSignatureEventHandler value)
Parameters
Type | Name | Description |
---|---|---|
PdfSignatureEventHandler | value |
ReplaceEmptySignature(Stream, String, Stream, String, IPdfExternalSigner, List<X509Certificate2>)
Adds a signature content, where the allocation was already reserved with an empty signature in a PDF document. This method has to be only used for deferred signing.
Declaration
public static void ReplaceEmptySignature(Stream inputFileStream, string pdfPassword, Stream outputFileStream, string signatureName, IPdfExternalSigner externalSigner, List<X509Certificate2> publicCertificates)
Parameters
Type | Name | Description |
---|---|---|
System.IO.Stream | inputFileStream | The stream containing the PDF document to load. |
System.String | pdfPassword | The password (user or owner) of the encrypted document. |
System.IO.Stream | outputFileStream | The stream where to save the PDF document. |
System.String | signatureName | Name of the signature. |
IPdfExternalSigner | externalSigner | The interface providing to sign externally. |
System.Collections.Generic.List<System.Security.Cryptography.X509Certificates.X509Certificate2> | publicCertificates | The x509 public certificates. |
Remarks
Signature field must be last signature
Examples
//Create external signer
IPdfExternalSigner externalSignature = new ExternalSigner("SHA1");
List<X509Certificate2> certificates = new List<X509Certificate2>();
// Add public certificates
certificates.Add(new X509Certificate2(new X509Certificate2("certificate.pfx", "syncfusion")));
// Create output file
FileStream outputFile = new FileStream("output.pdf", FileMode.Create, FileAccess.Write);
// Read input file to deferred sign
FileStream inputFile = new FileStream("input.pdf", FileMode.Open, FileAccess.Read);
// Deferred signing
PdfSignature.ReplaceEmptySignature(inputFile, "password", outputFile, "Signature", externalSignature, certificates);
//Create external signer
Dim externalSignature As IPdfExternalSigner = New ExternalSigner("SHA1")
Dim certificates As List(Of X509Certificate2) = New List(Of X509Certificate2)
// Add public certificates
certificates.Add(New X509Certificate2(New X509Certificate2("certificate.pfx", "syncfusion")))
// Create output file
Dim outputFile As FileStream = New FileStream("output.pdf", FileMode.Create, FileAccess.Write)
// Read input file to deferred sign
Dim inputFile As FileStream = New FileStream("input.pdf", FileMode.Open, FileAccess.Read)
// Deferred signing
PdfSignature.ReplaceEmptySignature(inputFile, "password", outputFile, "Signature", externalSignature, certificates)
ReplaceEmptySignature(Stream, String, Stream, String, IPdfExternalSigner, List<X509Certificate2>, Boolean)
Adds a signature content, where the allocation was already reserved with an empty signature in a PDF document. This method has to be only used for deferred signing.
Declaration
public static void ReplaceEmptySignature(Stream inputFileStream, string pdfPassword, Stream outputFileStream, string signatureName, IPdfExternalSigner externalSigner, List<X509Certificate2> publicCertificates, bool isEncodeSignature)
Parameters
Type | Name | Description |
---|---|---|
System.IO.Stream | inputFileStream | The stream containing the PDF document to load. |
System.String | pdfPassword | The password (user or owner) of the encrypted document. |
System.IO.Stream | outputFileStream | The stream where to save the PDF document. |
System.String | signatureName | Name of the signature. |
IPdfExternalSigner | externalSigner | The interface providing to sign externally. |
System.Collections.Generic.List<System.Security.Cryptography.X509Certificates.X509Certificate2> | publicCertificates | The x509 public certificates. |
System.Boolean | isEncodeSignature | Flag to encode signed data. |
Remarks
If an encoded signature flag is disabled, then the external signer signed bytes should be PKCS7 encoded.
Examples
//Create external signer
IPdfExternalSigner externalSignature = new ExternalSigner("SHA1");
List<X509Certificate2> certificates = new List<X509Certificate2>();
// Add public certificates
certificates.Add(new X509Certificate2(new X509Certificate2("certificate.pfx", "syncfusion")));
// Create output file
FileStream outputFile = new FileStream("output.pdf", FileMode.Create, FileAccess.Write);
// Read input file to deferred sign
FileStream inputFile = new FileStream("input.pdf", FileMode.Open, FileAccess.Read);
// Deferred signing
PdfSignature.ReplaceEmptySignature(inputFile, "password", outputFile, "Signature", externalSignature, certificates, false);
//Create external signer
Dim externalSignature As IPdfExternalSigner = New ExternalSigner("SHA1")
Dim certificates As List(Of X509Certificate2) = New List(Of X509Certificate2)
// Add public certificates
certificates.Add(New X509Certificate2(New X509Certificate2("certificate.pfx", "syncfusion")))
// Create output file
Dim outputFile As FileStream = New FileStream("output.pdf", FileMode.Create, FileAccess.Write)
// Read input file to deferred sign
Dim inputFile As FileStream = New FileStream("input.pdf", FileMode.Open, FileAccess.Read)
// Deferred signing
PdfSignature.ReplaceEmptySignature(inputFile, "password", outputFile, "Signature", externalSignature, certificates, False)
Events
ComputeHash
The event raised on the time of signing certificate to the PDF document.
Declaration
public event PdfSignatureEventHandler ComputeHash
Event Type
Type |
---|
PdfSignatureEventHandler |
Examples
//Load the existing PDF documnt.
PdfLoadedDocument document = new PdfLoadedDocument("Input.pdf");
//Get the page.
PdfLoadedPage page = document.Pages[0] as PdfLoadedPage;
//Create a new PDF signature instance.
PdfSignature signature = new PdfSignature(document, page, null, "Sig1");
//Set the signature bounds.
signature.Bounds = new RectangleF(0, 0, 200, 100);
//Call the compute hash event.
signature.ComputeHash += Signature_ComputeHash;
//Save the document.
document.Save("output.pdf");
//Close the document.
document.Close(true);
//ComputeHash event handler.
private void Signature_ComputeHash(object sender, PdfSignatureEventArgs ars)
{
//Get the document bytes.
byte[] documentBytes = ars.Data;
//Generate hash.
byte[] hash = SHA256.Create().ComputeHash(ars.Data);
//Include the signed data to PDF.
ars.SignedData = GetSignature(hash);
}
'Load the existing PDF documnt.
Dim document As New PdfLoadedDocument("Input.pdf")
'Get the page.
Dim page As PdfLoadedPage = TryCast(document.Pages(0), PdfLoadedPage)
'Create a new PDF signature instance.
Dim signature As New PdfSignature(document, page, Nothing, "Sig1")
'Set the signature bounds.
signature.Bounds = New RectangleF(0, 0, 200, 100)
'Call the compute hash event.
AddHandler signature.ComputeHash , AddressOf Signature_ComputeHash
'Save the document.
document.Save("output.pdf")
'Close the document.
document.Close(True)
//ComputeHash event handler.
Private Sub Signature_ComputeHash(ByVal sender As Object, ByVal ars As PdfSignatureEventArgs)
'Get the document bytes.
Dim documentBytes As Byte() = ars.Data
'Generate hash.
Dim hash As Byte() = SHA256.Create().ComputeHash(ars.Data)
'Include the signed data to PDF.
ars.SignedData = GetSignature(hash)
End Sub