Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ BenchmarkDotNet.Artifacts/
project.lock.json
project.fragment.lock.json
artifacts/
**/Properties/launchSettings.json

*_i.c
*_p.c
Expand Down
1 change: 1 addition & 0 deletions CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @DevExpressExampleBot
Binary file modified Images/screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
55 changes: 38 additions & 17 deletions Readme.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<!-- default badges list -->
![](https://img.shields.io/endpoint?url=https://codecentral.devexpress.com/api/v1/VersionRange/274919030/24.2.1%2B)
[![](https://img.shields.io/badge/Open_in_DevExpress_Support_Center-FF7200?style=flat-square&logo=DevExpress&logoColor=white)](https://supportcenter.devexpress.com/ticket/details/T902911)
[![](https://img.shields.io/badge/📖_How_to_use_DevExpress_Examples-e9f6fc?style=flat-square)](https://docs.devexpress.com/GeneralInformation/403183)
[![](https://img.shields.io/badge/💬_Leave_Feedback-feecdd?style=flat-square)](#does-this-example-address-your-development-requirementsobjectives)
Expand All @@ -10,30 +9,52 @@ This example prints and exports a report in a browser without previewing it on a

![Screenshot](Images/screenshot.png)

## Print
## Run the Project

Run the following command from the *ServerApp* folder:

```cmd
dotnet run
```

Run the following commands from the *react-app* folder:

```cmd
npm install
mpm run dev
```

Open your browser and navigate to the URL specified in the command output to see the result.

## Implementation Details

### Export Operations

The user selects the format from the drop-down list and clicks the **Export the report** button to send the format to the server-side controller. The controller calls the export method for the selected format and sends the file back to the browser.

### Print Operations

On the **server side**, a controller performs the following actions:
- [creates a report](https://docs.devexpress.com/XtraReports/2440/get-started-with-devexpress-reporting/create-a-report-from-a-to-z);
- [exports the report to PDF](https://docs.devexpress.com/XtraReports/2574/detailed-guide-to-devexpress-reporting/store-and-distribute-reports/export-reports/export-to-pdf) with the [XtraReport.ExportToPdfAsync](https://docs.devexpress.com/XtraReports/DevExpress.XtraReports.UI.XtraReport.ExportToPdfAsync.overloads) method;
- sends the PDF file back to the client.
- [Creates a report](https://docs.devexpress.com/XtraReports/2440/get-started-with-devexpress-reporting/create-a-report-from-a-to-z).
- [Exports the report to PDF](https://docs.devexpress.com/XtraReports/2574/detailed-guide-to-devexpress-reporting/store-and-distribute-reports/export-reports/export-to-pdf) with the [XtraReport.ExportToPdfAsync](https://docs.devexpress.com/XtraReports/DevExpress.XtraReports.UI.XtraReport.ExportToPdfAsync.overloads) method.
- Sends the PDF file back to the client.

On the **client side**, a user can do one of the following:

On the **client-side**, a user can do one of the following:

* Print a report in a new tab.
Click a button to call the client-side `window.Open(url, "_blank")` method to open a new window that contains a PDF file and print the window content.

* Print a report in iFrame.
Click a button to load a PDF file in the `HTMLIFrameElement` and print its content.
Click the **Print the report in a new tab** button to call the client-side `window.Open(url, "_blank")` method to open a new window that contains a PDF file and print the window content.

* Print a report in iFrame.

## Export
Click the **Print via iFrame** button to load a PDF file in the `HTMLIFrameElement` and print its content.

The user selects the format and clicks a button to send the format to the server-side controller. The controller calls the export method for the selected format and sends the file back to the browser.

## Files to Review

- [HomeComponent.jsx](dxSampleReactReportingPrintWithoutPreview/ClientApp/src/components/HomeComponent.jsx)
- [HomeController.cs](dxSampleReactReportingPrintWithoutPreview/Controllers/HomeController.cs)
- [HomeComponent.jsx](react-app/src/components/HomeComponent.jsx)
- [HomeController.cs](ServerApp/Controllers/HomeController.cs)

## Documentation

Expand All @@ -46,9 +67,9 @@ The user selects the format and clicks a button to send the format to the server
- [Reporting for Web (React) - Document Viewer](https://github.com/DevExpress-Examples/reporting-document-viewer-in-javascript-with-react)
- [How to Print and Export a Report in the ASP.NET Core Application without the Document Viewer](https://github.com/DevExpress-Examples/Reporting-AspNetCore-Print-Without-Preview)
<!-- feedback -->
## Does this example address your development requirements/objectives?

[<img src="https://www.devexpress.com/support/examples/i/yes-button.svg"/>](https://www.devexpress.com/support/examples/survey.xml?utm_source=github&utm_campaign=reporting-react-print-without-preview&~~~was_helpful=yes) [<img src="https://www.devexpress.com/support/examples/i/no-button.svg"/>](https://www.devexpress.com/support/examples/survey.xml?utm_source=github&utm_campaign=reporting-react-print-without-preview&~~~was_helpful=no)

## Does this example address your development requirements/objectives?
[<img src="https://www.devexpress.com/support/examples/i/yes-button.svg"/>](https://www.devexpress.com/support/examples/survey.xml?utm_source=github&utm_campaign=reporting-react-print-without-preview&~~~was_helpful=yes) [<img src="https://www.devexpress.com/support/examples/i/no-button.svg"/>](https://www.devexpress.com/support/examples/survey.xml?utm_source=github&utm_campaign=reporting-react-print-without-preview&~~~was_helpful=no)
(you will be redirected to DevExpress.com to submit your response)
<!-- feedback end -->
25 changes: 0 additions & 25 deletions Reporting-React-Print-Without-Preview.sln

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,92 +1,92 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using DevExpress.XtraPrinting;
using DevExpress.XtraReports.UI;
using dxSampleReactReportingPrintWithoutPreview.Model;
using dxSampleReactReportingPrintWithoutPreview.PredefinedReports;
using Microsoft.AspNetCore.Mvc;
namespace dxSampleReactReportingPrintWithoutPreview.Controllers
{
[Route("api/[controller]")]
public class HomeController : Controller
{
public IActionResult Index()
{
return View();
}
public IActionResult Error()
{
ViewData["RequestId"] = Activity.Current?.Id ?? HttpContext.TraceIdentifier;
return View();
}
[HttpGet("[action]")]
public async Task<object> Print()
{
var report = new TestReport();
using (var ms = new MemoryStream())
{
await report.ExportToPdfAsync(ms, new DevExpress.XtraPrinting.PdfExportOptions { ShowPrintDialogOnOpen = true });
return File(ms.ToArray(), System.Net.Mime.MediaTypeNames.Application.Pdf);
}
}
[HttpGet("[action]")]
public ActionResult Export(string format = "pdf")
{
format = format.ToLower();
XtraReport report = new TestReport();
string contentType = string.Format("application/{0}", format);
using (MemoryStream ms = new MemoryStream())
{
switch (format)
{
case "pdf":
contentType = "application/pdf";
report.ExportToPdf(ms);
break;
case "docx":
contentType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
report.ExportToDocx(ms);
break;
case "xls":
contentType = "application/vnd.ms-excel";
report.ExportToXls(ms);
break;
case "xlsx":
contentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
report.ExportToXlsx(ms);
break;
case "rtf":
report.ExportToRtf(ms);
break;
case "mht":
contentType = "message/rfc822";
report.ExportToMht(ms);
break;
case "html":
contentType = "text/html";
report.ExportToHtml(ms);
break;
case "txt":
contentType = "text/plain";
report.ExportToText(ms);
break;
case "csv":
contentType = "text/plain";
report.ExportToCsv(ms);
break;
case "png":
contentType = "image/png";
report.ExportToImage(ms, new ImageExportOptions() { Format = System.Drawing.Imaging.ImageFormat.Png });
break;
}
return File(ms.ToArray(), contentType);
}
}
}
}
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using DevExpress.XtraPrinting;
using DevExpress.XtraReports.UI;
using ServerApp.Model;
using ServerApp.PredefinedReports;
using Microsoft.AspNetCore.Mvc;

namespace ServerApp.Controllers
{
[Route("api/[controller]")]
public class HomeController : Controller
{
public IActionResult Index()
{
return View();
}

public IActionResult Error()
{
ViewData["RequestId"] = Activity.Current?.Id ?? HttpContext.TraceIdentifier;
return View();
}
[HttpGet("[action]")]
public async Task<object> Print()
{
var report = new TestReport();
using (var ms = new MemoryStream())
{
await report.ExportToPdfAsync(ms, new DevExpress.XtraPrinting.PdfExportOptions { ShowPrintDialogOnOpen = true });
return File(ms.ToArray(), System.Net.Mime.MediaTypeNames.Application.Pdf);
}
}
[HttpGet("[action]")]
public ActionResult Export(string format = "pdf")
{
format = format.ToLower();
XtraReport report = new TestReport();
string contentType = string.Format("application/{0}", format);
using (MemoryStream ms = new MemoryStream())
{
switch (format)
{
case "pdf":
contentType = "application/pdf";
report.ExportToPdf(ms);
break;
case "docx":
contentType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
report.ExportToDocx(ms);
break;
case "xls":
contentType = "application/vnd.ms-excel";
report.ExportToXls(ms);
break;
case "xlsx":
contentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
report.ExportToXlsx(ms);
break;
case "rtf":
report.ExportToRtf(ms);
break;
case "mht":
contentType = "message/rfc822";
report.ExportToMht(ms);
break;
case "html":
contentType = "text/html";
report.ExportToHtml(ms);
break;
case "txt":
contentType = "text/plain";
report.ExportToText(ms);
break;
case "csv":
contentType = "text/plain";
report.ExportToCsv(ms);
break;
case "png":
contentType = "image/png";
report.ExportToImage(ms, new ImageExportOptions() { Format = System.Drawing.Imaging.ImageFormat.Png });
break;
}
return File(ms.ToArray(), contentType);
}
}
}
}
45 changes: 45 additions & 0 deletions ServerApp/Controllers/ReportingControllers.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using DevExpress.DataAccess.Sql;
using System.Collections.Generic;
using DevExpress.AspNetCore.Reporting.QueryBuilder;
using DevExpress.AspNetCore.Reporting.ReportDesigner;
using DevExpress.AspNetCore.Reporting.ReportDesigner.Native.Services;
using DevExpress.AspNetCore.Reporting.QueryBuilder.Native.Services;
using DevExpress.XtraReports.Web.ReportDesigner;
using DevExpress.XtraReports.Web.ReportDesigner.Services;
using DevExpress.AspNetCore.Reporting.WebDocumentViewer;
using DevExpress.AspNetCore.Reporting.WebDocumentViewer.Native.Services;
using Microsoft.AspNetCore.Mvc;

namespace ServerApp.Controllers {
public class CustomWebDocumentViewerController : WebDocumentViewerController {
public CustomWebDocumentViewerController(IWebDocumentViewerMvcControllerService controllerService) : base(controllerService) {
}
}
public class CustomReportDesignerController : ReportDesignerController {
public CustomReportDesignerController(IReportDesignerMvcControllerService controllerService) : base(controllerService) {
}

[HttpPost("[action]")]
public IActionResult GetDesignerModel([FromForm]string reportUrl, [FromServices] IReportDesignerModelBuilder designerModelBuilder, [FromForm] ReportDesignerSettingsBase designerModelSettings) {
var ds = new SqlDataSource("NWindConnectionString");

// Create a SQL query to access the Products data table.
SelectQuery query = SelectQueryFluentBuilder.AddTable("Products").SelectAllColumnsFromTable().Build("Products");
ds.Queries.Add(query);
ds.RebuildResultSchema();

var designerModel = designerModelBuilder.Report(reportUrl)
.DataSources(dataSources => {
dataSources.Add("Northwind", ds);
})
.BuildModel();
designerModel.Assign(designerModelSettings);
return DesignerModel(designerModel);
}
}

public class CustomQueryBuilderController : QueryBuilderController {
public CustomQueryBuilderController(IQueryBuilderMvcControllerService controllerService) : base(controllerService) {
}
}
}
Loading