xtrareports-devexpress-dot-xtrareports-dot-web-dot-webdocumentviewer-8d483727.md
A service that allows you to handle and log report processing and document generation events in the Web Document Viewer control.
Namespace : DevExpress.XtraReports.Web.WebDocumentViewer
Assembly : DevExpress.XtraReports.v25.2.Web.dll
NuGet Package : DevExpress.Web.Reporting.Common
public class WebDocumentViewerOperationLogger
Public Class WebDocumentViewerOperationLogger
You can use a WebDocumentViewerOperationLogger class descendant to perform necessary actions at all stages of the Document Viewer lifecycle. You can modify the report and document settings, and execute custom code before a document is built, exported, or printed.
For this, create the WebDocumentViewerOperationLogger class descendant, override appropriate methods related to your task, and register the class as a service in your application.
using DevExpress.XtraReports.Web.WebDocumentViewer;
using DevExpress.XtraPrinting;
using System;
// ...
public class MyOperationLogger : WebDocumentViewerOperationLogger {
public override void ExportDocument(string documentId, string format, DevExpress.XtraPrinting.ExportOptions options, PrintingSystemBase printingSystem) {
if (format == "printpdf") {
// A customer clicked the "Print" or "Print Page" button
}
base.ExportDocument(documentId, format, options, printingSystem);
}
}
Imports DevExpress.XtraReports.Web.WebDocumentViewer
Imports DevExpress.XtraPrinting
Imports System;
' ...
Public Class MyOperationLogger
Inherits WebDocumentViewerOperationLogger
Public Overrides Sub ExportDocument(documentId As String, format As String, options As ExportOptions, printingSystem As PrintingSystemBase)
If format == "printpdf" Then
' A customer clicked the "Print" or "Print Page" button
End If
MyBase.ExportDocument(documentId, format, options, printingSystem)
End Sub
End Class
The following example restricts report export to any format except PDF. It demonstrates a server-side method that is preferable to a method that uses a client-side API in certain scenarios.
Override the ExportDocument method in the WebDocumentViewerOperationLogger descendant:
using DevExpress.XtraReports.Web.WebDocumentViewer;
using DevExpress.XtraPrinting;
using System;
// ...
public class MyOperationLogger : WebDocumentViewerOperationLogger {
public override void ExportDocument(string documentId, string format, ExportOptions options, PrintingSystemBase printingSystem) {
if (format != "pdf") {
throw new NotSupportedException(String.Format("Export to {0} format is not allowed!", format.ToUpper()));
}
// Specify the default PDF export options.
options.Pdf.Assign(new PdfExportOptions());
base.ExportDocument(documentId, format, options, printingSystem);
}
}
Imports DevExpress.XtraReports.Web.WebDocumentViewer
Imports DevExpress.XtraPrinting
Imports System;
' ...
Public Class MyOperationLogger
Inherits WebDocumentViewerOperationLogger
Public Overrides Sub ExportDocument(documentId As String, format As String, options As ExportOptions, printingSystem As PrintingSystemBase)
If format <> "pdf" Then
Throw New NotSupportedException([String].Format("Export to {0} format is not allowed!", format.ToUpper()))
End If
' Specify the default PDF export options.
options.Pdf.Assign(New PdfExportOptions())
MyBase.ExportDocument(documentId, format, options, printingSystem)
End Sub
End Class
If you need to build report documents synchronously, override the BuildStarting method instead. This may be necessary when you need to access HttpContext in the report control’s BeforePrint event handler.
Register the MyOperationLogger service at application startup:
using DevExpress.XtraReports.Web.WebDocumentViewer;
// ...
protected void Application_Start(object sender, System.EventArgs e) {
// ...
DefaultWebDocumentViewerContainer.RegisterSingleton<WebDocumentViewerOperationLogger, MyOperationLogger>();
}
Imports DevExpress.XtraReports.Web.WebDocumentViewer
' ...
Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
DefaultWebDocumentViewerContainer.RegisterSingleton(Of WebDocumentViewerOperationLogger, MyOperationLogger)()
End Sub
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddSingleton<WebDocumentViewerOperationLogger, MyOperationLogger>();
var app = builder.Build();
View Example: Reporting for ASP.NET MVC - How to implement a custom authorization service
Object WebDocumentViewerOperationLogger
See Also
WebDocumentViewerOperationLogger Members
IWebDocumentViewerAuthorizationService
Register Services in the Document Viewer (ASP.NET Web Forms)
Register Services in the Document Viewer (ASP.NET MVC)