Back to Devexpress

Document Viewer Integration (Node.js Package Manager)

xtrareports-119824-web-reporting-knockout-reporting-document-viewer-document-viewer-integration-with-nodejs-package-manager.md

latest4.8 KB
Original Source

Document Viewer Integration (Node.js Package Manager)

  • Mar 24, 2025
  • 5 minutes to read

You can use the HTML5 Document Viewer in JavaScript based on the server-side model. Create two projects:

  • A server (backend) project
  • A client (frontend) part that includes all the necessary styles, scripts, and HTML-templates

Server (Backend) Part

Use the DevExpress CLI Template

You can use DevExpress CLI Templates to create an ASP.NET Core back-end application. Begin with the steps below:

  1. Install DevExpress ASP.NET Core project templates from nuget.org:

  2. Create a back-end Reporting application for a Document Viewer:

  3. Enable cross-origin requests (CORS). Specify the policy that allows any local application to access the report’s back-end. Use the SetIsOriginAllowed method to set it up.

  4. To run the server-side application, run the following command:

Use Visual Studio Template

To create a back-end application from a Microsoft or DevExpress Template in Visual Studio, review the following help topics:

Client (Frontend) Part

The following steps describe how to configure and host the client part:

  1. Install Node.js and npm if they do not exist on your machine.

  2. Install the Webpack CLI globally with the following commands:

  3. Create a folder for a client-side project. In this example, the folder’s name is ClientSide.

  4. Create a package.json configuration file in the created folder and list the following third-party packages the Web Document Viewer requires:

  5. Navigate to your folder, open the console, and run the command below to install packages:

  6. Create a webpack.config.js file and specify configuration settings as shown below. Define the index.js file as the bundle’s entry point (this file is created later) and the bundle.js file as the output file.

  7. Create a View file (the index.html file in this example) and specify this View’s HTML template. In the body section, use the dxReportViewer binding with the viewerOptions parameter and link the bundle script file (bundle.js) specified in the previous step.

  8. Add a new JavaScript file (index.js*) to provide data to the View. Link the modules, create the viewerOptions variable, and activate the Knockout bindings.

  9. Create a new style.css file and link the styles.

  10. create the bundle with the following command:

  11. Host your client-side part on the web server.

  12. For the example to work correctly, run the backend project followed by the client part.

Troubleshooting

You may encounter the following issues:

Page Is Blank

The Document Viewer page is blank. The following error message is displayed at the bottom of the page:

Could not open report ‘TestReport’

Check the following:

  • The backend application is up and running.
  • The backend application runs on the port specified in the host setting of the Document Viewer component.
  • The application’s URI is compliant with the CORS policy specified in your back-end application.
  • The reportUrl setting value matches an existing report. For the backend application, ensure that either the Reports folder contains a reportUrl.repx file or the ReportsFactory.Reports dictionary contains the reportUrl entry (if the back-end application originated from the DevExpress template).
  • The version of DevExpress npm packages should match the version of NuGet packages. Enable Development Mode to check for a library version mismatch on every request to the server. For details, review the following help topic: Server-Side Libraries Version.

Refer to the following topic for more information: Troubleshooting.