Exporting a Report to PDF
Our sample projects and report templates can help you learn the basics of working with our products.Reports can be rendered and exported to PDF entirely on the server. This example renders a template and writes the PDF to a file.
Exporting the document. Load and render the report, configure the requested export format, and deliver the generated bytes as a file, stream, or web response.
Exporting the document. Load and render the report, configure the requested export format, and deliver the generated bytes as a file, stream, or web response.
var Stimulsoft = require('stimulsoft-reports-js');
var report = new Stimulsoft.Report.StiReport();
report.loadFile("SimpleList.mrt");
report.renderAsync(() => {
report.exportDocumentAsync((pdfData) => {
var buffer = Buffer.from(pdfData);
fs.writeFileSync('./SimpleList.pdf', buffer);
}, Stimulsoft.Report.StiExportFormat.Pdf);
});exportDocumentAsync returns the PDF as a byte array; wrapping it in a Node Buffer and calling fs.writeFileSync saves it to disk. This is the basis for server-side report delivery, e-mail attachments and scheduled exports.