corelibraries-devexpress-dot-xtraprinting-de59abc5.md
A service that allows the XRPageInfo control to display custom information.
Namespace : DevExpress.XtraPrinting
Assembly : DevExpress.Printing.v25.2.Core.dll
NuGet Package : DevExpress.Printing.Core
public abstract class PageInfoDataProviderBase
Public MustInherit Class PageInfoDataProviderBase
The following code displays the name of a logged in user instead of a user under whose account the web server runs in an ASP.NET MVC application. The PageInfoDataProviderBase service processes the PageInfo bricks, and returns information from the HttpContext about the current user.
using System.Web;
using DevExpress.XtraPrinting;
class CustomPageInfoDataProvider : PageInfoDataProviderBase
{
readonly HttpContext httpContext;
public CustomPageInfoDataProvider(HttpContext httpContext)
{
this.httpContext = httpContext;
}
public override string GetText(PrintingSystemBase ps, PageInfoTextBrickBase brick)
{
if (brick.PageInfo != PageInfo.UserName)
{
return null;
}
if (httpContext == null)
return "<No Information>";
var user = httpContext.User;
if (user == null || user.Identity == null)
return "<Please enable Forms or Windows security>";
var identity = user.Identity;
return identity.IsAuthenticated
? identity.Name
: "<Guest>";
}
}
Imports DevExpress.XtraPrinting
Friend Class CustomPageInfoDataProvider
Inherits PageInfoDataProviderBase
Private ReadOnly httpContext As HttpContext
Public Sub New(ByVal httpContext As HttpContext)
Me.httpContext = httpContext
End Sub
Public Overrides Function GetText(ByVal ps As PrintingSystemBase,
ByVal brick As PageInfoTextBrickBase) As String
If brick.PageInfo <> PageInfo.UserName Then
Return Nothing
End If
If httpContext Is Nothing Then
Return "<No Information>"
End If
Dim user = httpContext.User
If user Is Nothing OrElse user.Identity Is Nothing Then
Return "<Please enable Forms or Windows security>"
End If
Dim identity = user.Identity
Return If(identity.IsAuthenticated, identity.Name, "<Guest>")
End Function
End Class
To add the custom page info data provider to a report’s Printing System, call the PrintingSystemBase.AddService method in the WebDocumentViewerOperationLogger.BuildStarting method body of a custom WebDocumentViewerOperationLogger implementation.
using System;
using System.Web;
using DevExpress.XtraPrinting;
using DevExpress.XtraReports.UI;
using DevExpress.XtraReports.Web.WebDocumentViewer;
class CustomWebDocumentViewerOperationLogger : WebDocumentViewerOperationLogger
{
public override Action BuildStarting(string reportId, XtraReport report, ReportBuildProperties buildProperties)
{
var httpContext = HttpContext.Current;
return () => GenerateBuildStatingAction(report, httpContext);
}
static void GenerateBuildStatingAction(XtraReport report, HttpContext httpContext)
{
report.PrintingSystem.AddService(typeof(PageInfoDataProviderBase), new CustomPageInfoDataProvider(httpContext));
}
}
Imports DevExpress.XtraPrinting
Imports DevExpress.XtraReports.UI
Imports DevExpress.XtraReports.Web.WebDocumentViewer
Friend Class CustomWebDocumentViewerOperationLogger
Inherits WebDocumentViewerOperationLogger
Public Overrides Function BuildStarting(ByVal reportId As String,
ByVal report As XtraReport,
ByVal buildProperties As ReportBuildProperties) As Action
Dim httpContext = System.Web.HttpContext.Current
Return Sub() GenerateBuildStatingAction(report, httpContext)
End Function
Private Shared Sub GenerateBuildStatingAction(ByVal report As XtraReport,
ByVal httpContext As HttpContext)
report.PrintingSystem.AddService(GetType(PageInfoDataProviderBase),
New CustomPageInfoDataProvider(httpContext))
End Sub
End Class
To configure a report before document creation, add the custom operation logger to the DefaultWebDocumentViewerContainer at application startup.
using DevExpress.Web.Mvc;
using WebDocumentViewer_UserName.Services;
using DevExpress.XtraReports.Web.WebDocumentViewer;
// ...
protected void Application_Start() {
// ...
DefaultWebDocumentViewerContainer.RegisterSingleton<WebDocumentViewerOperationLogger, CustomWebDocumentViewerOperationLogger>();
DefaultWebDocumentViewerContainer.DisableCachedDocumentSource();
// ...
}
Imports DevExpress.Web.Mvc
Imports DevExpress.XtraReports.Web.WebDocumentViewer
Imports WebDocumentViewer_UserName_VB.Services
' ...
Sub Application_Start()
' ...
DefaultWebDocumentViewerContainer.Register(Of WebDocumentViewerOperationLogger, CustomWebDocumentViewerOperationLogger)()
DefaultWebDocumentViewerContainer.DisableCachedDocumentSource()
' ...
End Sub
View Example: How to Display the Name of the Current Logged in User in a Report
Object PageInfoDataProviderBase
See Also
PageInfoDataProviderBase Members
WebDocumentViewerOperationLogger