This example shows how to export a report to the PDF format from code. You need to create the report object of the StiReport type, then load the report template file by calling the loadFile() method. After this, you should render the report by calling the renderAsync() method of the report object:
// Create a new report instance
var report = new Stimulsoft.Report.StiReport();
// Load report from url
report.loadFile("../reports/SimpleList.mrt");
// Render report
report.renderAsync(function () {
	document.getElementById("savePdf").disabled = false;
});

For exporting a report to the PDF format you can use the exportDocumentAsync() function of the StiReport object. As the first argument, you need to specify the callback function that will be called after the export is complete. The second argument indicates the export format. For example, the result is saved to the file using the StiObject.saveAs() method. This method was added in the Stimulsoft library, you can use it for saving files:
<button id="savePdf" onclick="saveReportPdf()" disabled>Save PDF report to file</button>
function saveReportPdf() {
	// Export to PDF
	report.exportDocumentAsync(function (pdfData) {
		// Get report file name
		var fileName = report.reportAlias;
		// Save data to file
		Stimulsoft.System.StiObject.saveAs(pdfData, fileName + ".pdf", "application/pdf");
	}, Stimulsoft.Report.StiExportFormat.Pdf);
}

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

Exporting a Report to PDF

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.