IPdfSignatureOptionsProviderAsync.GetAvailableOptionsAsync() Method
Returns a key/PdfSignatureOptions object dictionary, asynchronously.
Namespace: DevExpress.XtraReports.Web.WebDocumentViewer
Assembly: DevExpress.XtraReports.v24.1.dll
NuGet Package: DevExpress.Reporting.Core
Declaration
Returns
Type | Description |
---|---|
Task<Dictionary<String, PdfSignatureOptions>> | A Task that returns a dictionary with value pairs: a certificate identifier and the corresponding PdfSignatureOptions object. |
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:
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:
During export to PDF, XRPdfSignature is converted to a signature with the specified settings: