This sample project shows how to export and print the report from code without using the report viewer. For this action, it is enough to use the special StiNetCoreReportResponse class that implements the methods for report exporting and printing. These methods take the input of all the necessary parameters to configure exporting and printing the report.

The special StiNetCoreReportResponse class contains methods to export report in any format and print report to PDF and HTML. For example, implementing it for one report in order to compare them. Add two links for each print mode and three links for various export formats:
<div class="row">
	<div class="col-md-4">
		<h2>Print to PDF</h2>
		<p>@Html.ActionLink("Print", "OnGetPrintPdf")</p>
	</div>
	<div class="col-md-4">
		<h2>Print to HTML</h2>
		<p>@Html.ActionLink("Print", "OnGetPrintHtml")</p>
	</div>
</div>
<hr />
<div class="row">
	<div class="col-md-4">
		<h2>Export to PDF</h2>
		<p>@Html.ActionLink("Export", "OnGetExportPdf")</p>
	</div>
	<div class="col-md-4">
		<h2>Export to HTML</h2>
		<p>@Html.ActionLink("Export", "OnGetExportHtml")</p>
	</div>
	<div class="col-md-4">
		<h2>Export to Excel</h2>
		<p>@Html.ActionLink("Export", "OnGetExportXls")</p>
	</div>
</div>

To get the report, the GetReport() method was used. This method loads the report template, loads the XML data file and registers this data for loaded report:
private StiReport GetReport()
{
	var reportPath = StiNetCoreHelper.MapPath(this, "Reports/TwoSimpleLists.mrt");
	var report = new StiReport();
	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 two action methods - OnGetPrintPdf and OnGetPrintHtml:
public IActionResult OnGetPrintPdf()
{
	var report = this.GetReport();
	return StiNetCoreReportResponse.PrintAsPdf(report);
}

public IActionResult OnGetPrintHtml()
{
	var report = this.GetReport();
	return StiNetCoreReportResponse.PrintAsHtml(report);
}

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

public IActionResult OnGetExportHtml()
{
	var report = this.GetReport();
	return StiNetCoreReportResponse.ResponseAsHtml(report);
}

public IActionResult OnGetExportXls()
{
	var report = this.GetReport();
	return StiNetCoreReportResponse.ResponseAsXls(report);
}

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

Exporting and Printing a Report 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.