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 StiReportResponse 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 two links for various export formats:
<div align="center">
    <button @onclick="ExportDashboardAsHTML">Export as HTML</button>   <button @onclick="ExportDashboardAsPDF">Export as PDF</button>   <button @onclick="PrintDashboard">Print</button>
    <br /><br />
    <input id="responseAsFile" type="checkbox" @bind="responseAsFile"><label for="responseAsFile">Response as File</label>
    <br /><br />
    <p>@message</p>
</div>

Now we need to determine the actions that will be invoked when clicking on links. For printing we will use the PrintDashboard method:
private async Task PrintDashboard()
{
	// Create empty dashboard object
	var report = StiReport.CreateNewDashboard();

	// Load dashboard template
	var reportBytes = await Http.GetByteArrayAsync("Dashboards/DashboardChristmas.mrt");
	report.Load(reportBytes);

	// Print dashboard
	StiReportResponse.PrintAsPdf(report);

	message = new MarkupString("The dashboard printed");
}

For exporting, we will use two action methods - ExportDashboardAsPDF and ExportDashboardAsHTML. 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:
private async Task ExportDashboardAsHTML()
{
	// Create empty dashboard object
	var report = StiReport.CreateNewDashboard();

	// Load dashboard template
	var reportBytes = await Http.GetByteArrayAsync("Dashboards/DashboardChristmas.mrt");
	report.Load(reportBytes);

	StiReportResponse.ResponseAsHtml(report, responseAsFile);
	message = new MarkupString("Export to HTML is completed.");
}

private async Task ExportDashboardAsPDF()
{
	// Create empty dashboard object
	var report = StiReport.CreateNewDashboard();

	// Load dashboard template
	var reportBytes = await Http.GetByteArrayAsync("Dashboards/DashboardChristmas.mrt");
	report.Load(reportBytes);

	StiReportResponse.ResponseAsPdf(report, responseAsFile);
	message = new MarkupString("Export to PDF is completed.");
}

Auf dem Screenshot unten Sie können das Ergebnis des Beispiel-Codes ansehen:

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.