Class PdfSignature
- Namespace
- Syncfusion.Pdf.Security
- Assembly
- Syncfusion.Pdf.Portable.dll
Represents a digital signature used for signing a PDF document.
public class PdfSignature
- Inheritance
-
PdfSignature
- Inherited Members
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)
Remarks
This API is not supported in WinRT, Windows Phone, Xamarin, Universal Windows Platform and Silverlight.
Constructors
PdfSignature()
Initializes a new instance of the PdfSignature class.
[Obsolete("Please use PdfSignature(PdfPage page, PdfCertificate cert, string signatureName)instead")]
public PdfSignature()
Remarks
This constructor is not supported in WinRT, Windows Phone, Xamarin, Universal Windows Platform and Silverlight.
- See Also
PdfSignature(PdfDocumentBase, PdfPageBase, PdfCertificate, string)
Initializes a new instance of the PdfSignature class with the PDF document, page, certificate and the signature name.
public PdfSignature(PdfDocumentBase document, PdfPageBase page, PdfCertificate certificate, string signatureName)
Parameters
document
PdfDocumentBaseThe document, which has the page.
page
PdfPageBaseThe page.
certificate
PdfCertificateThe certificate.
signatureName
stringThe name of the signature.
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")
Remarks
This constructor is not supported in WinRT, Windows Phone, Xamarin, Universal Windows Platform and Silverlight.
- 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.
public PdfSignature(PdfDocumentBase document, PdfPageBase page, PdfCertificate certificate, string signatureName, PdfLoadedSignatureField loadedField)
Parameters
document
PdfDocumentBaseThe loaded document, which has the page.
page
PdfPageBaseThe page.
certificate
PdfCertificateThe certificate.
signatureName
stringThe name of the signature.
loadedField
PdfLoadedSignatureFieldThe name of the loaded signature field
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")
Remarks
This constructor is not supported in WinRT, Windows Phone, Xamarin, Universal Windows Platform and Silverlight.
- See Also
PdfSignature(PdfLoadedPage, string)
Initializes a new instance of the PdfSignature class with the Loaded page and the signature name.
public PdfSignature(PdfLoadedPage page, string signatureName)
Parameters
page
PdfLoadedPageThe current pdf loaded page where signature will be added.
signatureName
stringName of the signature.
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);
Remarks
This constructor is not supported in WinRT, Windows Phone, Xamarin, Universal Windows Platform and Silverlight.
- See Also
PdfSignature(PdfPage, PdfCertificate, string)
Initializes a new instance of the PdfSignature class with the page, certificate and the signature name.
public PdfSignature(PdfPage page, PdfCertificate cert, string signatureName)
Parameters
page
PdfPageThe current pdf page where signature will be replaced.
cert
PdfCertificateThe pdf certificate.
signatureName
stringName of the signature.
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")
Remarks
This constructor is not supported in WinRT, Windows Phone, Xamarin, Universal Windows Platform and Silverlight.
- See Also
PdfSignature(PdfPage, string)
Initializes a new instance of the PdfSignature class with the page, certificate and the signature name.
public PdfSignature(PdfPage page, string signatureName)
Parameters
page
PdfPageThe current pdf page where signature will be replaced.
signatureName
stringName of the signature.
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")
Remarks
This constructor is not supported in WinRT, Windows Phone, Xamarin, Universal Windows Platform and Silverlight.
- See Also
Properties
Appearance
Gets the signature Appearance.[Read-Only]
public PdfAppearance Appearance { get; }
Property Value
- PdfAppearance
A PdfAppearance object defines signature`s appearance.
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)
Remarks
This property is not supported in WinRT, Windows Phone, Xamarin, Universal Windows Platform and Silverlight.
- See Also
Appearence
Gets the signature Appearance.[Read-Only]
[Obsolete("Please use Appearance instead")]
public PdfAppearance Appearence { get; }
Property Value
- PdfAppearance
A PdfAppearance object defines signature`s appearance.
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)
Remarks
This property is not supported in WinRT, Windows Phone, Xamarin, Universal Windows Platform and Silverlight.
- See Also
Bounds
Gets or sets bounds of the signature.
public RectangleF Bounds { get; set; }
Property Value
- RectangleF
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)
Remarks
This property is not supported in WinRT, Windows Phone, Xamarin, Universal Windows Platform and Silverlight.
- See Also
Certificate
Gets or sets the signing certificate.
public PdfCertificate Certificate { get; set; }
Property Value
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)
Remarks
This property is not supported in WinRT, Windows Phone, Xamarin, Universal Windows Platform and Silverlight.
- See Also
Certificated
Gets or sets a value indicating certificate document or not. NOTE: Works only with Adobe Reader 7.0.8 or higher.
public bool Certificated { get; set; }
Property Value
- bool
certificate document if true.
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)
Remarks
This property is not supported in WinRT, Windows Phone, Xamarin, Universal Windows Platform and Silverlight.
- 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.
public string ContactInfo { get; set; }
Property Value
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)
Remarks
This property is not supported in WinRT, Windows Phone, Xamarin, Universal Windows Platform and Silverlight.
- See Also
DocumentPermissions
Gets or sets the permission for certificated document.
public PdfCertificationFlags DocumentPermissions { get; set; }
Property Value
- PdfCertificationFlags
The document permission.
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)
Remarks
This property is not supported in WinRT, Windows Phone, Xamarin, Universal Windows Platform and Silverlight.
- See Also
EnableLtv
Get or Set LTV to signed document.
public bool EnableLtv { get; set; }
Property Value
- See Also
EnableValidationAppearance
Gets or sets the signature validation appearance
public bool EnableValidationAppearance { get; set; }
Property Value
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)
- See Also
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
public uint EstimatedSignatureSize { set; }
Property Value
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)
- See Also
IsLocked
Gets or sets a value indicating whether to lock the signature or not.
public bool IsLocked { get; set; }
Property Value
- bool
lock signature if true.
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)
Remarks
This property is not applicable for existing signed signature fields.
- See Also
Location
Gets or sets signature location on the PDF page.
public PointF Location { get; set; }
Property Value
- PointF
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)
Remarks
This porperty is not supported in WinRT, Windows Phone, Xamarin, Universal Windows Platform and Silverlight.
- See Also
LocationInfo
Gets or sets the physical location of the signing.
public string LocationInfo { get; set; }
Property Value
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)
Remarks
This property is not supported in WinRT, Windows Phone, Xamarin, Universal Windows Platform and Silverlight.
- See Also
Reason
Gets or sets reason of signing.
public string Reason { get; set; }
Property Value
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)
Remarks
This property is not supported in WinRT, Windows Phone, Xamarin, Universal Windows Platform and Silverlight.
- See Also
Settings
Gets or sets the signature settings
public PdfSignatureSettings Settings { get; }
Property Value
- 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)
- See Also
SignedDate
Get signed Date
public DateTime SignedDate { get; }
Property Value
- See Also
SignedName
Gets or sets the signed name
public string SignedName { get; set; }
Property Value
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)
- See Also
TimeStampServer
Gets or sets time stamping server unique resource identifier.
public TimeStampServer TimeStampServer { get; set; }
Property Value
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)
Remarks
This property is not supported in WinRT, Windows Phone, Xamarin, Universal Windows Platform and Silverlight.
- See Also
Visible
Gets a value indicating whether signature visible or not.[Read-Only]
public bool Visible { get; }
Property Value
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)
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.
- See Also
Methods
AddExternalSigner(IPdfExternalSigner, List<X509Certificate2>, byte[])
Add External Signer for signature
public void AddExternalSigner(IPdfExternalSigner signer, List<X509Certificate2> publicCertificates, byte[] Ocsp)
Parameters
signer
IPdfExternalSignerpublicCertificates
List<X509Certificate2>Ocsp
byte[]
- See Also
CreateLongTermValidity(List<X509Certificate2>, RevocationType, bool)
Create long term validation of the signature.
public void CreateLongTermValidity(List<X509Certificate2> certificates, RevocationType type, bool includePublicCertificates = false)
Parameters
certificates
List<X509Certificate2>A list of X.509 certificates to process.
type
RevocationTypeThe revocation type.
includePublicCertificates
boolA 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);
- See Also
CreateLongTermValidity(List<X509Certificate2>, bool)
Create long term validation of the signature.
public void CreateLongTermValidity(List<X509Certificate2> certificates, bool includePublicCertificates = false)
Parameters
certificates
List<X509Certificate2>A list of X.509 certificates to process.
includePublicCertificates
boolA 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);
- See Also
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.
public static void ReplaceEmptySignature(Stream inputFileStream, string pdfPassword, Stream outputFileStream, string signatureName, IPdfExternalSigner externalSigner, List<X509Certificate2> publicCertificates)
Parameters
inputFileStream
StreamThe stream containing the PDF document to load.
pdfPassword
stringThe password (user or owner) of the encrypted document.
outputFileStream
StreamThe stream where to save the PDF document.
signatureName
stringName of the signature.
externalSigner
IPdfExternalSignerThe interface providing to sign externally.
publicCertificates
List<X509Certificate2>The x509 public certificates.
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)
Remarks
Signature field must be last signature
- See Also
ReplaceEmptySignature(Stream, string, Stream, string, IPdfExternalSigner, List<X509Certificate2>, bool)
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.
public static void ReplaceEmptySignature(Stream inputFileStream, string pdfPassword, Stream outputFileStream, string signatureName, IPdfExternalSigner externalSigner, List<X509Certificate2> publicCertificates, bool isEncodeSignature)
Parameters
inputFileStream
StreamThe stream containing the PDF document to load.
pdfPassword
stringThe password (user or owner) of the encrypted document.
outputFileStream
StreamThe stream where to save the PDF document.
signatureName
stringName of the signature.
externalSigner
IPdfExternalSignerThe interface providing to sign externally.
publicCertificates
List<X509Certificate2>The x509 public certificates.
isEncodeSignature
boolFlag to encode signed data.
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)
Remarks
If an encoded signature flag is disabled, then the external signer signed bytes should be PKCS7 encoded.
- See Also
Events
ComputeHash
The event raised on the time of signing certificate to the PDF document.
public event PdfSignatureEventHandler ComputeHash
Event Type
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
- See Also