This example shows how to perform the required actions before printing or exporting the report in the viewer.

First you need to add the StiNetCoreViewer component to the view page. Also you need to pass the StiNetCoreViewerOptions object to the constructor. In the options you should set the next actions: GetReport, PrintReport, ExportReport and ViewerEvent. The last two actions will be called accordingly at report printing and exporting:
@using Stimulsoft.Report.Mvc;

...

@Html.StiNetCoreViewer(new StiNetCoreViewerOptions()
{
	Actions =
	{
		GetReport = "GetReport",
		PrintReport = "PrintReport",
		ExportReport = "ExportReport",
		ViewerEvent = "ViewerEvent"
	}
})

In the options above we define several actions, and we need to add it in the controller.

The GetReport action loads the report and returns the answer to the client part of the viewer using the GetReportResult() static method. In the parameters of this method, the report object should be passed:
public IActionResult GetReport()
{
	// Create the report object
	var report = new StiReport();
	report.Load(StiNetCoreHelper.MapPath(this, "Reports/TwoSimpleLists.mrt"));

	return StiNetCoreViewer.GetReportResult(report);
}

The ViewerEvent action handles all the viewer events (switching pages, zooming, etc.) and returns the answer to the client using the ViewerEventResult() static method:
public IActionResult ViewerEvent()
{
	return StiNetCoreViewer.ViewerEventResult(this);
}

The PrintReport action will be invoked when you print the report through menu of the viewer. In this action, you can get the report object and perform any action, for example connect to data. To prepare the answer for the client you should use the PrintReportResult() static method:
public IActionResult PrintReport()
{
	var report = StiNetCoreViewer.GetReportObject(this);
	
	// Some actions with report when printing
	
	return StiNetCoreViewer.PrintReportResult(this, report);
}

The ExportEvent action will be invoked when you export the report in any format through menu of the viewer. You can get the report object and perform any action. Also you can get the action parameters of the viewer and, for example, perform some action at the PDF report export. To prepare the answer for the client, you should use the ExportReportResult() static method:
public IActionResult ExportReport()
{
	var report = StiNetCoreViewer.GetReportObject(this);
	var parameters = StiNetCoreViewer.GetRequestParams(this);

	// Some actions with report when exporting
	report.ReportName = "MyReportName";
	report.ReportAlias = report.ReportName;

	if (parameters.ExportFormat == StiExportFormat.Pdf)
	{
		// Change some export settings when exporting to PDF
		var settings = (StiPdfExportSettings)StiNetCoreViewer.GetExportSettings(this);
		settings.CreatorString = "My Company";

		return StiNetCoreViewer.ExportReportResult(this, report, settings);
	}
            
	return StiNetCoreViewer.ExportReportResult(this, report);
}

In the screenshot below you can see the result of the sample code:

Managing Report Printing and Exporting

By using this website, you agree to the use of cookies for analytics and personalized content. Cookies store useful information on your computer to help us improve efficiency and usability. For more information, please read the privacy policy and cookie policy.