Back to Devexpress

PdfSignature.Reason Property

officefileapi-devexpress-dot-pdf-dot-pdfsignature-1280d22c.md

latest7.0 KB
Original Source

PdfSignature.Reason Property

Gets or sets the reason for a document signature.

Namespace : DevExpress.Pdf

Assembly : DevExpress.Pdf.v25.2.Core.dll

NuGet Package : DevExpress.Pdf.Core

Declaration

csharp
public string Reason { get; set; }
vb
Public Property Reason As String

Property Value

TypeDescription
String

A String object that is the reason for a document signature.

|

Remarks

Use the Reason property to specify the reason for a document signature. For example: “I agree…”

Example

This example illustrates how to add a visual signature to a PDF document.

To accomplish this task, do the following:

  • Create a PDF Document API component represented by an instance of the PdfDocumentProcessor class.

  • Load a document from a file using the PdfDocumentProcessor.LoadDocument method.

  • Create a certificate using a certificate file name and a password to access the certificate.

  • Create a document visual signature using one of the PdfSignature constructor overloads that takes 4 arguments. For example, using a certificate, image data represented by a byte array, and specifying the page number and signature bounds. The signature bounds are represented by a PdfOrientedRectangle object. You can specify the rotation angle for the signature (in radians) when creating a PdfOrientedRectangle object.

  • Specify signing location, contact info and reason using the PdfSignature.Location, PdfSignature.ContactInfo and PdfSignature.Reason properties, respectively.

  • Save the signed document with signing information by calling the PdfDocumentProcessor.SaveDocument method.

  • C#

  • VB.NET

csharp
using DevExpress.Pdf;
using System;
using System.IO;
using System.Security.Cryptography.X509Certificates;

namespace PDFSignature {
    class Program {
        static void Main(string[] args) {

            // Create a PDF document processor.
            using (PdfDocumentProcessor documentProcessor = new PdfDocumentProcessor()) {

                // Load a PDF document. 
                documentProcessor.LoadDocument(@"..\..\Demo.pdf");

                // Create a visual signature using certificate, image data, and specifying page number, signature bounds and rotation angle. 
                X509Certificate2 certificate = new X509Certificate2(@"..\..\SignDemo.pfx", "dxdemo");
                byte[] imageData = File.ReadAllBytes("..\\..\\Signature.png");
                int pageNumber = 1;
                int angleInDegrees = 45; 
                double angleInRadians = angleInDegrees * (Math.PI / 180);
                PdfOrientedRectangle signatureBounds = new PdfOrientedRectangle(new PdfPoint(620, 210), 250, 90, angleInRadians);
                PdfSignature signature = new PdfSignature(certificate, imageData, pageNumber, signatureBounds);

                // Specify signing location, contact info and reason.
                signature.Location = "USA";
                signature.ContactInfo = "[email protected]";
                signature.Reason = "Approved";

                // Save the signed document.
                documentProcessor.SaveDocument(@"..\..\SignedDocument.pdf", new PdfSaveOptions() { Signature = signature });
            }
        }
    }
}
vb
Imports DevExpress.Pdf
Imports System
Imports System.IO
Imports System.Security.Cryptography.X509Certificates

Namespace PDFSignature
    Class Program
        Private Shared Sub Main(ByVal args As String())
            Using documentProcessor As PdfDocumentProcessor = New PdfDocumentProcessor()
                documentProcessor.LoadDocument("..\..\Demo.pdf")
                Dim certificate As X509Certificate2 = New X509Certificate2("..\..\SignDemo.pfx", "dxdemo")
                Dim imageData As Byte() = File.ReadAllBytes("..\..\Signature.png")
                Dim pageNumber As Integer = 1
                Dim angleInDegrees As Integer = 45
                Dim angleInRadians As Double = angleInDegrees * (Math.PI / 180)
                Dim signatureBounds As PdfOrientedRectangle = New PdfOrientedRectangle(New PdfPoint(620, 210), 250, 90, angleInRadians)
                Dim signature As PdfSignature = New PdfSignature(certificate, imageData, pageNumber, signatureBounds)
                signature.Location = "USA"
                signature.ContactInfo = "[email protected]"
                signature.Reason = "Approved"
                documentProcessor.SaveDocument("..\..\SignedDocument.pdf", New PdfSaveOptions() With {
                    .Signature = signature
                })
            End Using
        End Sub
    End Class
End Namespace

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the Reason property.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

pdf-document-api-add-visual-signature-to-pdf-document/CS/PDFSignature/Program.cs#L31

csharp
signature.ContactInfo = "[email protected]";
signature.Reason = "Approved";

pdf-document-api-add-visual-signature-to-pdf-document/VB/PDFSignature/Program.vb#L23

vb
signature.ContactInfo = "[email protected]"
signature.Reason = "Approved"
documentProcessor.SaveDocument("..\..\..\SignedDocument.pdf", New DevExpress.Pdf.PdfSaveOptions() With {.Signature = signature})

See Also

PdfSignature Class

PdfSignature Members

DevExpress.Pdf Namespace