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 void PrintDashboard()
{
	// Create empty dashboard object
	var report = StiReport.CreateNewDashboard();

	// Load dashboard template
	report.Load("Dashboards/DashboardChristmas.mrt");

	// 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 void ExportDashboardAsHTML()
{
	// Create empty dashboard object
	var report = StiReport.CreateNewDashboard();

	// Load dashboard template
	report.Load("Dashboards/DashboardChristmas.mrt");

	if (responseAsFile)
	{
		// Response as HMTL file
		StiReportResponse.ResponseAsHtml(report);

		message = new MarkupString("Export to HTML is completed.");
	}
	else
	{
		// Export to HTML file
		var _exportFilePath = $"Dashboards/ChristmasDashboard_{DateTime.Now.ToString("yyyy-dd-MM_HH-mm-ss")}.html";
		report.ExportDocument(Stimulsoft.Report.StiExportFormat.Html, _exportFilePath);

		message = new MarkupString("The exported dashboard is saved to a file: 
" + _exportFilePath); } } private void ExportDashboardAsPDF() { // Create empty dashboard object var report = StiReport.CreateNewDashboard(); // Load dashboard template report.Load("Dashboards/DashboardChristmas.mrt"); if (responseAsFile) { // Response as PDF file StiReportResponse.ResponseAsPdf(report); message = new MarkupString("Export to PDF is completed."); } else { // Export to PDF file var _exportFilePath = $"Dashboards/ChristmasDashboard_{DateTime.Now.ToString("yyyy-dd-MM_HH-mm-ss")}.pdf"; report.ExportDocument(Stimulsoft.Report.StiExportFormat.Pdf, _exportFilePath); message = new MarkupString("The exported dashboard is saved to a file:
" + _exportFilePath); } }

На скриншоте ниже Вы можете увидеть результат выполнения данного кода:

Exporting and Printing a Dashboard from Code

Используя этот сайт, вы соглашаетесь на использование файлов Cookie для аналитики и персонализированного контента. Файлы Cookie хранят полезную информацию на вашем компьютере, чтобы помочь нам повысить эффективность и удобство использования. Для получения дополнительной информации, пожалуйста, прочтите Конфиденциальность и Использование Cookie.