Class PdfSignature
Represents a digital signature used for signing a PDF document.
Inheritance
Inherited Members
Namespace: Syncfusion.Pdf.Security
Assembly: Syncfusion.Pdf.Base.dll
Syntax
public class PdfSignature
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
[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.
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)
Declaration
public PdfSignature(PdfLoadedPage page, string signatureName)
Parameters
Type | Name | Description |
---|---|---|
PdfLoadedPage | page | |
System.String | signatureName |
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
[Obsolete("Please use Appearance instead")]
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 | Description |
---|---|
System.Drawing.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 | Description |
---|---|
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 | Description |
---|---|
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 | Description |
---|---|
System.Boolean |
EnableValidationAppearance
Gets or sets the signature validation appearance
Declaration
public bool EnableValidationAppearance { get; set; }
Property Value
Type | Description |
---|---|
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 | Description |
---|---|
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 | Description |
---|---|
System.Drawing.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 | Description |
---|---|
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 | Description |
---|---|
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
Declaration
public PdfSignatureSettings Settings { get; }
Property Value
Type | Description |
---|---|
PdfSignatureSettings |
SignedDate
Get signed Date
Declaration
public DateTime SignedDate { get; }
Property Value
Type | Description |
---|---|
System.DateTime |
SignedName
Gets or sets the signed name
Declaration
public string SignedName { get; set; }
Property Value
Type | Description |
---|---|
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 | Description |
---|---|
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 | Description |
---|---|
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
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>)
Create Long Term Validation of the signature.
Declaration
public void CreateLongTermValidity(List<X509Certificate2> certificates)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.List<System.Security.Cryptography.X509Certificates.X509Certificate2> | certificates | X509 certificate data |
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);
ReplaceEmptySignature(Stream, String, Stream, String, IPdfExternalSigner, List<X509Certificate2>)
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 | |
System.String | pdfPassword | |
System.IO.Stream | outputFileStream | |
System.String | signatureName | |
IPdfExternalSigner | externalSigner | |
System.Collections.Generic.List<System.Security.Cryptography.X509Certificates.X509Certificate2> | publicCertificates |
ReplaceEmptySignature(Stream, String, Stream, String, IPdfExternalSigner, List<X509Certificate2>, Boolean)
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 | |
System.String | pdfPassword | |
System.IO.Stream | outputFileStream | |
System.String | signatureName | |
IPdfExternalSigner | externalSigner | |
System.Collections.Generic.List<System.Security.Cryptography.X509Certificates.X509Certificate2> | publicCertificates | |
System.Boolean | isEncodeSignature |
Events
ComputeHash
The event raised on the time of signing certificate to the PDF document.
Declaration
public event PdfSignatureEventHandler ComputeHash
Event Type
Type | Description |
---|---|
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