Skip to main content
A newer version of this page is available. .
All docs
V23.1

IPdfSignatureOptionsProviderAsync Interface

When implemented, provides asynchronous access to digital signatures in the Web Document Viewer.

Namespace: DevExpress.XtraReports.Web.WebDocumentViewer

Assembly: DevExpress.XtraReports.v23.1.dll

NuGet Package: DevExpress.Reporting.Core

Declaration

public interface IPdfSignatureOptionsProviderAsync

Remarks

In MVC and Web Forms applications, use a synchronous approach to get a dictionary of available signatures. If you use asynchronous code to get the signatures, pass false to the ConfigureAwait method throughout the entire chain of methods:

public async Task<Dictionary<string, PdfSignatureOptions>> GetAvailableOptionsAsync() {
    var signatures = await GetMySignaturesAsync(...).ConfigureAwait(false);
    return signatures;
}

Example

The following example shows how to sign a document exported to PDF from the Web Document Viewer’s UI:

View Example: How to Sign the Exported PDF Document

Implement the IPdfSignatureOptionsProviderAsync interface to register signatures. The GetAvailableOptionsAsync() method returns a dictionary of value pairs: signature certificate identifiers and PdfSignatureOptions objects:

using System;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
using DevExpress.XtraPrinting;
using DevExpress.XtraReports.Web.WebDocumentViewer;
using Microsoft.AspNetCore.Hosting;

namespace SignPdfDocumentExample.Services {
    public class CustomPdfSignatureOptionsProviderAsync : IPdfSignatureOptionsProviderAsync {
        readonly Dictionary<string, PdfSignatureOptions> signatures = new Dictionary<string, PdfSignatureOptions>();
        public CustomPdfSignatureOptionsProviderAsync(IWebHostEnvironment webHostEnvironment) {
            var signatureDictionaryPath = Path.Join(webHostEnvironment.ContentRootPath, "Signatures");
            signatures.Add(Guid.NewGuid().ToString(), new PdfSignatureOptions() {
                Certificate = new System.Security.Cryptography.X509Certificates.X509Certificate2(Path.Combine(signatureDictionaryPath, "certificate.pfx"), "123"),
                ContactInfo = "Jane Cooper",
            });
            signatures.Add(Guid.NewGuid().ToString(), new PdfSignatureOptions() {
                Certificate = new System.Security.Cryptography.X509Certificates.X509Certificate2(Path.Combine(signatureDictionaryPath, "certificate.pfx"), "123"),
                ContactInfo = "John Smith",
                Location = "Australia",
                Reason = "I Agree",
                ImageSource = DevExpress.XtraPrinting.Drawing.ImageSource.FromFile(Path.Combine(signatureDictionaryPath, "John_Smith.png"))
            });
        }

        public Task<Dictionary<string, PdfSignatureOptions>> GetAvailableOptionsAsync() {
            return Task.FromResult(signatures);
        }
    }
}

To sign a report, select a signature from the drop-down list in PDF Export Options:

Web Document Viewer - PDF Export Options - Signatures

During export to PDF, XRPdfSignature is converted to a signature with the specified settings:

Web Document Viewer - Signed Document

See Also