This sample project shows how to export and print the dashboard from code without using the viewer.

For this action, it is enough to use the special StiNetCoreReportResponse class. This class implements the static methods for dashboard exporting and printing that take the input of all the necessary parameters for configuration. For example, add a link for print and three links for various export formats:
<div class="row">
	<div class="col-md-4">
		<h2>Print to PDF</h2>
		<p>@Html.ActionLink("Print", "PrintPdf")</p>
	</div>
</div>
<hr />
<div class="row">
	<div class="col-md-4">
		<h2>Export to PDF</h2>
		<p>@Html.ActionLink("Export", "ExportPdf")</p>
	</div>
	<div class="col-md-4">
		<h2>Export to Excel</h2>
		<p>@Html.ActionLink("Export", "ExportExcel")</p>
	</div>
	<div class="col-md-4">
		<h2>Export to Image</h2>
		<p>@Html.ActionLink("Export", "ExportImage")</p>
	</div>
</div>

To get the dashboard, the GetDashboard() method was used. This method creates the new dashboard object and loads the dashboard template from the file:
private StiReport GetDashboard()
{
	var reportPath = StiNetCoreHelper.MapPath(this, "Dashboards/DashboardChristmas.mrt");
	var report = StiReport.CreateNewDashboard();
	report.Load(reportPath);

	return report;
}

Now we need to determine the actions that will be invoked when clicking on links. For printing we will use the PrintPdf method:
public IActionResult PrintPdf()
{
	var report = this.GetDashboard();
	return StiNetCoreReportResponse.PrintAsPdf(report);
}

For exporting, we will use three action methods - ExportPdf, ExportExcel, and ExportImage. These export formats are taken for example. Also, the methods of exporting a dashboard (and printing) can take, as input, export settings and other necessary parameters:
public IActionResult ExportPdf()
{
	var report = this.GetDashboard();
	return StiNetCoreReportResponse.ResponseAsPdf(report);
}

public IActionResult ExportExcel()
{
	var report = this.GetDashboard();
	return StiNetCoreReportResponse.ResponseAsExcel2007(report);
}

public IActionResult ExportImage()
{
	var report = this.GetDashboard();
	return StiNetCoreReportResponse.ResponseAsPng(report);
}

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

Exporting and Printing a Dashboard from Code

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.