Back to Devexpress

Print a Remotely Created Document

xtrareports-17015-desktop-reporting-common-features-printing-print-reports-in-wpf-print-a-remotely-created-document.md

latest4.1 KB
Original Source

Print a Remotely Created Document

  • Aug 18, 2023
  • 3 minutes to read

This tutorial illustrates how to use the Document Preview for WPF to publish a document that is generated remotely by the WCF report service.

Create a WPF Application

To get started with this tutorial, open an existing WPF Application with a print preview, or create a new one from scratch. To learn how to add a print preview to a WPF application, refer to the Document Preview tutorial.

Prepare the Server Part

  1. To add a server-side application to the solution, right-click the solution item in the Solution Explorer. In the invoked drop-down menu, point to Add , and then select NewProject.

  2. Next, add a report service to the server-side application. To do this, right-click the WebApplication1 item in the solution explorer. In the invoked drop-down menu, point to Add , and then select New Item.

  3. In the same way, add a report to the server-side application.

  4. Design a layout for the added report. For instructions on how to create different report layouts, refer to the Create Reports documentation section.

Prepare the Client Part

  1. Switch to the WPF project and handle the main window’s Loaded event. In the event handler, create a RemoteDocumentSource that the Document Preview uses to obtain document data from the server.

  2. To establish a connection to the server-side application, specify the following properties of the created RemoteDocumentSource.

  3. Assign the remote document source to the DocumentViewerControl.DocumentSource property of the Document Viewer Control.

  4. Next, call the RemoteDocumentSource.CreateDocument method to generate the document for the print preview.

The following code sample illustrates the described steps.

csharp
using DevExpress.ReportServer.Printing;
using System.Windows;
// ...

private void Window_Loaded(object sender, RoutedEventArgs e) {
    RemoteDocumentSource documentSource = new RemoteDocumentSource() {           
        ServiceUri = "http://localhost:53206/ReportService1.svc",
        ReportName = "WebApplication1.XtraReport1, WebApplication1"
    };
    documentPreview1.DocumentSource = documentSource;
    documentSource.CreateDocument();
}
vb
Imports DevExpress.ReportServer.Printing
Imports System.Windows
' ...

Private Sub Window_Loaded(ByVal sender As Object, ByVal e As RoutedEventArgs)
    Dim documentSource As New RemoteDocumentSource() With {.ServiceUri = "http://localhost:53206/ReportService1.svc", .ReportName = "WebApplication1.XtraReport1, WebApplication1"}
    documentPreview1.DocumentSource = documentSource
    documentSource.CreateDocument()
End Sub

Launch the Application and View the Result

The client-side print preview is now capable of obtaining documents created on the application’s server side.

To preview the document, run the application. To print or export the previewed report, use corresponding toolbar commands.

Limitations

When the Document Preview shows remotely created documents, it does not provide the following capabilities:

  • Change document page settings in the Page Setup dialog;
  • Scale the document content;
  • Display thumbnails;
  • Use editing fields;
  • Search for a specific text using the Search panel;
  • Add watermarks.