Table of Contents

Class PdfCertificate

Namespace
Syncfusion.Pdf.Security
Assembly
Syncfusion.Pdf.Portable.dll

Represents the Certificate object.

public class PdfCertificate
Inheritance
PdfCertificate
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();
//Create new PDF certificate instance.
PdfCertificate pdfCert = new PdfCertificate("Pdf.pfx", "syncfusion");
//Create new PDF signature instance.
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()
'Create new PDF certificate instance.
Dim pdfCert As PdfCertificate = New PdfCertificate("Pdf.pfx", "syncfusion")
'Create new PDF signature instance.
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

PdfCertificate(Stream, string)

Initializes a new instance of the PdfCertificate class with the path to the pfx file and the password.

public PdfCertificate(Stream certificate, string password)

Parameters

certificate Stream
password string

The password for pfx file.

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(certificateStream, "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(certificateStream, "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 constructor is not supported in WinRT and Silverlight.

See Also

PdfCertificate(Stream, string, KeyStorageFlags)

Initializes a new instance of the PdfCertificate class with the path to the pfx file,password and storageflag

public PdfCertificate(Stream certificate, string password, KeyStorageFlags storageFlag)

Parameters

certificate Stream
password string

The password for pfx file.

storageFlag KeyStorageFlags

The private key storage flag.

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(certificateStream, "123",KeyStorageFlags.DefaultKeySet);
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(certificateStream, "123",KeyStorageFlags.DefaultKeySet)
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 constructor is not supported in WinRT and Silverlight.

See Also

PdfCertificate(X509Certificate2)

Initialize the new instance of the PdfCertificate class.

public PdfCertificate(X509Certificate2 x509Certificate2)

Parameters

x509Certificate2 X509Certificate2

The X509 certificate.

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");
//Create a new PDF certificate instance using X509Certificate2 object.
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.";
//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")
'Create a new PDF certificate instance using X509Certificate2 object.
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."
'Save the document.
document.Save("output.pdf")
'Close the document.
document.Close(True)
See Also

Properties

IssuerName

Gets the certificate issuer's name.[Read-Only]

public string IssuerName { get; }

Property Value

string

The certificate issuer`s name.

Examples

PdfDocument doc = new PdfDocument();
PdfPage page = doc.Pages.Add();
PdfSolidBrush brush = new PdfSolidBrush(Color.Black);
PdfPen pen = new PdfPen(brush, 0.2f);
PdfFont font = new PdfStandardFont(PdfFontFamily.Courier, 12, PdfFontStyle.Regular);
PdfCertificate pdfCert = new PdfCertificate(@"PDF.pfx", "syncfusion");
PdfSignature signature = new PdfSignature(page, pdfCert, "Signature");
signature.Bounds = new RectangleF(new PointF(5, 5), page.Size);
signature.ContactInfo = "johndoe@owned.us";
signature.LocationInfo = "Honolulu, Hawaii";
signature.Reason = "I am author of this document.";
PdfGraphics g = signature.Appearence.Normal.Graphics;
string validto  = "Issuer Name: " + signature.Certificate.IssuerName.ToString()
string validfrom = "Valid From: " + signature.Certificate.ValidFrom.ToString();
doc.Pages[0].Graphics.DrawString(validfrom, font, pen, brush, 0, 90);
doc.Pages[0].Graphics.DrawString(validto, font, pen, brush, 0, 110);
doc.Pages[0].Graphics.DrawString(" Protected Document. Digitally signed Document.", font, pen, brush, 0, 130);
doc.Pages[0].Graphics.DrawString("* To validate Signature click on the signature on this page \n * To check Document Status \n click document status icon on the bottom left of the acrobat reader.", font, pen, brush, 0, 150);
// Save the PDF file.
doc.Save("Sample.pdf");
doc.Close(true);
Dim doc As PdfDocument = New PdfDocument()
Dim page As PdfPage = doc.Pages.Add()
Dim brush As PdfSolidBrush = New PdfSolidBrush(Color.Black)
Dim pen As PdfPen = New PdfPen(brush, 0.2f)
Dim font As PdfFont = New PdfStandardFont(PdfFontFamily.Courier, 12, PdfFontStyle.Regular)
Dim pdfCert As PdfCertificate = New PdfCertificate("PDF.pfx", "syncfusion")
Dim signature As PdfSignature = New PdfSignature(page, pdfCert, "Signature")
signature.Bounds = New RectangleF(New PointF(5, 5), page.Size)
signature.ContactInfo = "johndoe@owned.us"
signature.LocationInfo = "Honolulu, Hawaii"
signature.Reason = "I am author of this document."
Dim g As PdfGraphics = signature.Appearence.Normal.Graphics
Dim validto As String = "Issuer Name: " + signature.Certificate.IssuerName.ToString()
Dim validfrom As String = "Valid From: " + signature.Certificate.ValidFrom.ToString()
doc.Pages(0).Graphics.DrawString(validfrom, font, pen, brush, 0, 90)
doc.Pages(0).Graphics.DrawString(validto, font, pen, brush, 0, 110)
' Save the PDF file.
doc.Save("Sample.pdf")
doc.Close(True)

Remarks

This property is not supported in WinRT, Windows Phone, Xamarin, Universal Windows Platform and Silverlight.

See Also

SerialNumber

Gets the serial number of a certificate.[Read-Only]

public byte[] SerialNumber { get; }

Property Value

byte[]

The serial number of the certificate.

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 an existing PDF certificate.
PdfCertificate certificate = new PdfCertificate("certificate.Pfx", "password");
//Get the serial number of the certificate.
byte[] data = certificate.SerialNumber;
//Get the store certificate.
PdfCertificate storeCertificate = PdfCertificate.FindBySerialId(StoreType.MY, data);
//Creates a digital signature.
PdfSignature signature = new PdfSignature(document, page, storeCertificate, "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.";
//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 an existing PDF certificate.
Dim certificate As New PdfCertificate("certificate.Pfx", "password")
'Get the serial number of the certificate.
Dim data As Byte() = certificate.SerialNumber
'Get the store certificate.
Dim storeCertificate As PdfCertificate = PdfCertificate.FindBySerialId(StoreType.MY, data)
'Creates a digital signature.
Dim signature As New PdfSignature(document, page, storeCertificate, "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."
'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

SubjectName

Gets the certificate subject's name.[Read-Only]

public string SubjectName { get; }

Property Value

string

Examples

PdfDocument doc = new PdfDocument();
PdfPage page = doc.Pages.Add();
PdfSolidBrush brush = new PdfSolidBrush(Color.Black);
PdfPen pen = new PdfPen(brush, 0.2f);
PdfFont font = new PdfStandardFont(PdfFontFamily.Courier, 12, PdfFontStyle.Regular);
PdfCertificate pdfCert = new PdfCertificate(@"PDF.pfx", "syncfusion");
PdfSignature signature = new PdfSignature(page, pdfCert, "Signature");
signature.Bounds = new RectangleF(new PointF(5, 5), page.Size);
signature.ContactInfo = "johndoe@owned.us";
signature.LocationInfo = "Honolulu, Hawaii";
signature.Reason = "I am author of this document.";
PdfGraphics g = signature.Appearence.Normal.Graphics;
string validto  = "Issuer Name: " + signature.Certificate.IssuerName.ToString()
string validfrom = "Valid From: " + signature.Certificate.ValidFrom.ToString();
doc.Pages[0].Graphics.DrawString(validfrom, font, pen, brush, 0, 90);
doc.Pages[0].Graphics.DrawString(validto, font, pen, brush, 0, 110);
doc.Pages[0].Graphics.DrawString(" Protected Document. Digitally signed Document.", font, pen, brush, 0, 130);
doc.Pages[0].Graphics.DrawString("* To validate Signature click on the signature on this page \n * To check Document Status \n click document status icon on the bottom left of the acrobat reader.", font, pen, brush, 0, 150);
// Save the PDF file.
doc.Save("Sample.pdf");
doc.Close(true);
Dim doc As PdfDocument = New PdfDocument()
Dim page As PdfPage = doc.Pages.Add()
Dim brush As PdfSolidBrush = New PdfSolidBrush(Color.Black)
Dim pen As PdfPen = New PdfPen(brush, 0.2f)
Dim font As PdfFont = New PdfStandardFont(PdfFontFamily.Courier, 12, PdfFontStyle.Regular)
Dim pdfCert As PdfCertificate = New PdfCertificate("PDF.pfx", "syncfusion")
Dim signature As PdfSignature = New PdfSignature(page, pdfCert, "Signature")
signature.Bounds = New RectangleF(New PointF(5, 5), page.Size)
signature.ContactInfo = "johndoe@owned.us"
signature.LocationInfo = "Honolulu, Hawaii"
signature.Reason = "I am author of this document."
Dim g As PdfGraphics = signature.Appearence.Normal.Graphics
Dim validto As String = "Subject Name: " + signature.Certificate.SubjectName.ToString()
Dim validfrom As String = "Valid From: " + signature.Certificate.ValidFrom.ToString()
doc.Pages(0).Graphics.DrawString(validfrom, font, pen, brush, 0, 90)
doc.Pages(0).Graphics.DrawString(validto, font, pen, brush, 0, 110)
' Save the PDF file.
doc.Save("Sample.pdf")
doc.Close(True)

Remarks

This property is not supported in WinRT, Windows Phone, Xamarin, Universal Windows Platform and Silverlight.

See Also

ValidFrom

Gets the date and time after which the certificate is not valid.[Read-Only]

public DateTime ValidFrom { get; }

Property Value

DateTime

Examples

PdfDocument doc = new PdfDocument();
PdfPage page = doc.Pages.Add();
PdfSolidBrush brush = new PdfSolidBrush(Color.Black);
PdfPen pen = new PdfPen(brush, 0.2f);
PdfFont font = new PdfStandardFont(PdfFontFamily.Courier, 12, PdfFontStyle.Regular);
PdfCertificate pdfCert = new PdfCertificate(@"PDF.pfx", "syncfusion");
PdfSignature signature = new PdfSignature(page, pdfCert, "Signature");
signature.Bounds = new RectangleF(new PointF(5, 5), page.Size);
signature.ContactInfo = "johndoe@owned.us";
signature.LocationInfo = "Honolulu, Hawaii";
signature.Reason = "I am author of this document.";
PdfGraphics g = signature.Appearence.Normal.Graphics;
string validto  = "Version To: " + signature.Certificate.ValidTo.ToString()
string validfrom = "Valid From: " + signature.Certificate.ValidFrom.ToString();
doc.Pages[0].Graphics.DrawString(validfrom, font, pen, brush, 0, 90);
doc.Pages[0].Graphics.DrawString(validto, font, pen, brush, 0, 110);
doc.Pages[0].Graphics.DrawString(" Protected Document. Digitally signed Document.", font, pen, brush, 0, 130);
doc.Pages[0].Graphics.DrawString("* To validate Signature click on the signature on this page \n * To check Document Status \n click document status icon on the bottom left of the acrobat reader.", font, pen, brush, 0, 150);
// Save the PDF file.
doc.Save("Sample.pdf");
doc.Close(true);
Dim doc As PdfDocument = New PdfDocument()
Dim page As PdfPage = doc.Pages.Add()
Dim brush As PdfSolidBrush = New PdfSolidBrush(Color.Black)
Dim pen As PdfPen = New PdfPen(brush, 0.2f)
Dim font As PdfFont = New PdfStandardFont(PdfFontFamily.Courier, 12, PdfFontStyle.Regular)
Dim pdfCert As PdfCertificate = New PdfCertificate("PDF.pfx", "syncfusion")
Dim signature As PdfSignature = New PdfSignature(page, pdfCert, "Signature")
signature.Bounds = New RectangleF(New PointF(5, 5), page.Size)
signature.ContactInfo = "johndoe@owned.us"
signature.LocationInfo = "Honolulu, Hawaii"
signature.Reason = "I am author of this document."
Dim g As PdfGraphics = signature.Appearence.Normal.Graphics
Dim validto As String = "Version To: " + signature.Certificate.ValidTo.ToString()
Dim validfrom As String = "Valid From: " + signature.Certificate.ValidFrom.ToString()
doc.Pages(0).Graphics.DrawString(validfrom, font, pen, brush, 0, 90)
doc.Pages(0).Graphics.DrawString(validto, font, pen, brush, 0, 110)
doc.Pages(0).Graphics.DrawString(" Protected Document. Digitally signed Document.", font, pen, brush, 0, 130)
doc.Pages(0).Graphics.DrawString("* To validate Signature click on the signature on this page " + Constants.vbLf + " * To check Document Status " + Constants.vbLf + " click document status icon on the bottom left of the acrobat reader.", font, pen, brush, 0, 150)
' Save the PDF file.
doc.Save("Sample.pdf")
doc.Close(True)

Remarks

This property is not supported in WinRT, Windows Phone, Xamarin, Universal Windows Platform and Silverlight.

See Also

ValidTo

Gets the date and time before which the certificate is not valid.[Read-Only]

public DateTime ValidTo { get; }

Property Value

DateTime

Examples

PdfDocument doc = new PdfDocument();
PdfPage page = doc.Pages.Add();
PdfSolidBrush brush = new PdfSolidBrush(Color.Black);
PdfPen pen = new PdfPen(brush, 0.2f);
PdfFont font = new PdfStandardFont(PdfFontFamily.Courier, 12, PdfFontStyle.Regular);
PdfCertificate pdfCert = new PdfCertificate(@"PDF.pfx", "syncfusion");
PdfSignature signature = new PdfSignature(page, pdfCert, "Signature");
signature.Bounds = new RectangleF(new PointF(5, 5), page.Size);
signature.ContactInfo = "johndoe@owned.us";
signature.LocationInfo = "Honolulu, Hawaii";
signature.Reason = "I am author of this document.";
PdfGraphics g = signature.Appearence.Normal.Graphics;
string validto  = "Version To: " + signature.Certificate.ValidTo.ToString()
string validfrom = "Valid From: " + signature.Certificate.ValidFrom.ToString();
doc.Pages[0].Graphics.DrawString(validfrom, font, pen, brush, 0, 90);
doc.Pages[0].Graphics.DrawString(validto, font, pen, brush, 0, 110);
doc.Pages[0].Graphics.DrawString(" Protected Document. Digitally signed Document.", font, pen, brush, 0, 130);
doc.Pages[0].Graphics.DrawString("* To validate Signature click on the signature on this page \n * To check Document Status \n click document status icon on the bottom left of the acrobat reader.", font, pen, brush, 0, 150);
// Save the PDF file.
doc.Save("Sample.pdf");
doc.Close(true);
Dim doc As PdfDocument = New PdfDocument()
Dim page As PdfPage = doc.Pages.Add()
Dim brush As PdfSolidBrush = New PdfSolidBrush(Color.Black)
Dim pen As PdfPen = New PdfPen(brush, 0.2f)
Dim font As PdfFont = New PdfStandardFont(PdfFontFamily.Courier, 12, PdfFontStyle.Regular)
Dim pdfCert As PdfCertificate = New PdfCertificate("PDF.pfx", "syncfusion")
Dim signature As PdfSignature = New PdfSignature(page, pdfCert, "Signature")
signature.Bounds = New RectangleF(New PointF(5, 5), page.Size)
signature.ContactInfo = "johndoe@owned.us"
signature.LocationInfo = "Honolulu, Hawaii"
signature.Reason = "I am author of this document."
Dim g As PdfGraphics = signature.Appearence.Normal.Graphics
Dim validto As String = "Version To: " + signature.Certificate.ValidTo.ToString()
Dim validfrom As String = "Valid From: " + signature.Certificate.ValidFrom.ToString()
doc.Pages(0).Graphics.DrawString(validfrom, font, pen, brush, 0, 90)
doc.Pages(0).Graphics.DrawString(validto, font, pen, brush, 0, 110)
doc.Pages(0).Graphics.DrawString(" Protected Document. Digitally signed Document.", font, pen, brush, 0, 130)
doc.Pages(0).Graphics.DrawString("* To validate Signature click on the signature on this page " + Constants.vbLf + " * To check Document Status " + Constants.vbLf + " click document status icon on the bottom left of the acrobat reader.", font, pen, brush, 0, 150)
' Save the PDF file.
doc.Save("Sample.pdf")
doc.Close(True)

Remarks

This property is not supported in WinRT, Windows Phone, Xamarin, Universal Windows Platform and Silverlight.

See Also

Version

Gets the certificate's version number.[Read-Only]

public int Version { get; }

Property Value

int

Examples

PdfDocument doc = new PdfDocument();
PdfPage page = doc.Pages.Add();
PdfSolidBrush brush = new PdfSolidBrush(Color.Black);
PdfPen pen = new PdfPen(brush, 0.2f);
PdfFont font = new PdfStandardFont(PdfFontFamily.Courier, 12, PdfFontStyle.Regular);
PdfCertificate pdfCert = new PdfCertificate(@"PDF.pfx", "syncfusion");
PdfSignature signature = new PdfSignature(page, pdfCert, "Signature");
signature.Bounds = new RectangleF(new PointF(5, 5), page.Size);
signature.ContactInfo = "johndoe@owned.us";
signature.LocationInfo = "Honolulu, Hawaii";
signature.Reason = "I am author of this document.";
PdfGraphics g = signature.Appearence.Normal.Graphics;
string validto = "Version: " + signature.Certificate.Version.ToString();
string validfrom = "Valid From: " + signature.Certificate.ValidFrom.ToString();
doc.Pages[0].Graphics.DrawString(validfrom, font, pen, brush, 0, 90);
doc.Pages[0].Graphics.DrawString(validto, font, pen, brush, 0, 110);
doc.Pages[0].Graphics.DrawString(" Protected Document. Digitally signed Document.", font, pen, brush, 0, 130);
doc.Pages[0].Graphics.DrawString("* To validate Signature click on the signature on this page \n * To check Document Status \n click document status icon on the bottom left of the acrobat reader.", font, pen, brush, 0, 150);
// Save the PDF file.
doc.Save("Sample.pdf");
doc.Close(true);
Dim doc As PdfDocument = New PdfDocument()
Dim page As PdfPage = doc.Pages.Add()
Dim brush As PdfSolidBrush = New PdfSolidBrush(Color.Black)
Dim pen As PdfPen = New PdfPen(brush, 0.2f)
Dim font As PdfFont = New PdfStandardFont(PdfFontFamily.Courier, 12, PdfFontStyle.Regular)
Dim pdfCert As PdfCertificate = New PdfCertificate("PDF.pfx", "syncfusion")
Dim signature As PdfSignature = New PdfSignature(page, pdfCert, "Signature")
signature.Bounds = New RectangleF(New PointF(5, 5), page.Size)
signature.ContactInfo = "johndoe@owned.us"
signature.LocationInfo = "Honolulu, Hawaii"
signature.Reason = "I am author of this document."
Dim g As PdfGraphics = signature.Appearence.Normal.Graphics
Dim validto As String = "Version: " + signature.Certificate.Version.ToString()
Dim validfrom As String = "Valid From: " + signature.Certificate.ValidFrom.ToString()
doc.Pages(0).Graphics.DrawString(validfrom, font, pen, brush, 0, 90)
doc.Pages(0).Graphics.DrawString(validto, font, pen, brush, 0, 110)
doc.Pages(0).Graphics.DrawString(" Protected Document. Digitally signed Document.", font, pen, brush, 0, 130)
doc.Pages(0).Graphics.DrawString("* To validate Signature click on the signature on this page" + vbCrLf + " * To check Document Status" + vbCrLf + " click document status icon on the bottom left of the acrobat reader.", font, pen, brush, 0, 150)
' Save the PDF file.
doc.Save("Sample.pdf")
doc.Close(True)

Remarks

This property is not supported in WinRT, Windows Phone, Xamarin, Universal Windows Platform and Silverlight.

See Also

See Also