Skip to main content
All docs
V25.1
  • WebDocumentViewerOperationLogger.CustomizeExportDocumentOnFinish(String, String, ExportedDocument) Method

    Allows you to retrieve and modify export results.

    Namespace: DevExpress.XtraReports.Web.WebDocumentViewer

    Assembly: DevExpress.XtraReports.v25.1.Web.dll

    NuGet Package: DevExpress.Web.Reporting.Common

    Declaration

    public virtual void CustomizeExportDocumentOnFinish(
        string documentId,
        string exportOperationId,
        ExportedDocument exportedDocument
    )

    Parameters

    Name Type Description
    documentId String

    A String value that identifies a document.

    exportOperationId String

    A String value that identifies the export operation.

    exportedDocument ExportedDocument

    An exported document.

    Remarks

    Override the CustomizeExportDocumentOnFinish method to retrieve and modify the exported document.

    Example

    The following example shows how to sign the exported PDF document. Note that in this case the document is signed digitally without applying a visual signature.

    View Example: How to Sign the Exported PDF Document

    The following code implements the CustomViewerOperationLogger service that inherits the WebDocumentViewerOperationLogger class. The overridden CustomizeExportDocumentOnFinish method signs the exported PDF document with a PKCS#7 signature. The PdfDocumentSigner.SaveDocument methods takes the signature (the SaveDocument(String, PdfSignatureBuilder[]) object) as a parameter and saves the signed document.

    using System.IO;
    using DevExpress.Office.DigitalSignatures;
    using DevExpress.Pdf;
    using DevExpress.XtraReports.Web.ClientControls;
    using DevExpress.XtraReports.Web.WebDocumentViewer;
    using Microsoft.AspNetCore.Hosting;
    using Microsoft.AspNetCore.Http;
    using Microsoft.Extensions.Logging;
    
    namespace SignPdfDocumentExample.Services {
        public class CustomViewerOperationLogger : WebDocumentViewerOperationLogger {
            readonly ILogger<CustomViewerOperationLogger> logger;
            readonly IWebHostEnvironment webHostEnvironment;
    
            public CustomViewerOperationLogger(ILogger<CustomViewerOperationLogger> logger, IHttpContextAccessor httpContextAccessor, IWebHostEnvironment webHostEnvironment) {
                this.logger = logger;
                this.webHostEnvironment = webHostEnvironment;
            }
    
            public override void CustomizeExportDocumentOnFinish(string documentId, string exportOperationId, ExportedDocument exportedDocument) {
                if(exportedDocument.ContentType == "application/pdf") {
                    string certificateFile = Path.Join(webHostEnvironment.ContentRootPath, "Signatures", "certificate.pfx");
                    using(PdfDocumentSigner documentSigner = new PdfDocumentSigner(new MemoryStream(exportedDocument.Bytes))) {
                        var signer = new Pkcs7Signer(certificateFile, "123", HashAlgorithmType.SHA256);
                        PdfSignatureBuilder signature = new PdfSignatureBuilder(signer);
                        signature.ContactInfo = "John Smith";
                        signature.Reason = "I Agree";
                        MemoryStream stream = new MemoryStream();
                        documentSigner.SaveDocument(stream, signature);
                        exportedDocument.Bytes = stream.ToArray();
                    }
                    logger.LogInformation($"Exported document {documentId} signed with \"certificate.pfx\" signature certificate.");
                }
            }
        }
    }
    

    For more information on how to sign the document with the PDF Document API, refer to the following topic: Sign PDF Documents.

    See Also