This example shows how to export a report from code. First, load scripts:
@using Stimulsoft.Base
@using Stimulsoft.Report
@using Stimulsoft.Report.Web
@using Stimulsoft.Report.Blazor

Next, create buttons:
<div align="center">
	<button @onclick="ExportReportAsHTML">Export as HTML</button>
	<button @onclick="ExportReportAsPDF">Export as PDF</button>
	<br /><br />
	<p>@message</p>
</div>

After that, initialize JSRuntime service:
@code
{
    private MarkupString message;

    protected override async Task OnInitializedAsync()
    {
        await base.OnInitializedAsync();

        //Initialize JSRuntime service
        StiBlazorHelper.Initialize(JSRuntime);
    }

...

Then, use ResponseAs method to export report:
...

	private async Task ExportReportAsHTML()
    {
		message = new MarkupString("Processing...");
		
        //Create empty report object
        var report = new StiReport();

        //Load report template
        var reportBytes = await Http.GetByteArrayAsync("Reports/TwoSimpleLists.mrt");
        report.Load(reportBytes);

        //Render, without showing progress
        report.Render(false);

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

        message = new MarkupString("Export to HTML is completed.");
    }

    private async Task ExportReportAsPDF()
    {
		message = new MarkupString("Processing...");
	
        //Create empty report object
        var report = new StiReport();

        //Load report template
        var reportBytes = await Http.GetByteArrayAsync("Reports/TwoSimpleLists.mrt");
        report.Load(reportBytes);

        //Render, without showing progress
        report.Render(false);

        //Response as PDF file
        StiReportResponse.ResponseAsPdf(report);

        message = new MarkupString("Export to PDF is completed.");
    }
}

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

Exporting 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.