This example illustrates how to render a report and save the result to the HTML file. First of all, you should add Stimulsoft modules to the project. To do this, just use one universal package, all other dependencies will be loaded automatically:
// Stimulsoft Reports module
var Stimulsoft = require('stimulsoft-reports-js');
console.log("Stimulsoft Reports loaded");

For the correct rendering of reports and accurate calculation of the sizes of all elements, you should load the fonts you are going to use. In this example, the Roboto-Black font is used, load it using a special addOpentypeFontFile() static method. The font will be loaded and added to the internal font collection:
// Loading fonts
Stimulsoft.Base.StiFontCollection.addOpentypeFontFile("Roboto-Black.ttf");
console.log("Font loaded");

Now you need to create a new StiReport object and load the previously prepared report template using the loadFile() method. As an argument, specify the path to the MRT template file:
// Creating new report
var report = new Stimulsoft.Report.StiReport();
console.log("New report created");

// Loading report template
report.loadFile("SimpleList.mrt");
console.log("Report template loaded");

To render a report, call the asynchronous renderAsync() method, which will perform all the necessary actions. Also, you can specify a callback function in the method arguments, which will be called after rendering:
// Renreding report
report.renderAsync(() => {
    console.log("Report rendered. Pages count: ", report.renderedPages.count);

    ...
});

To save the rendered report to the HTML format, you first need to export the report. To do this, you can use the special exportDocument() method. The required format can be specified as an argument of the function, in this case, specify StiExportFormat.Html format. It is correct to call this method in the callback function after the report rendering is complete. You can save result to a file using standard methods for working with files:
// Renreding report
report.renderAsync(() => {
    ...

    // Export to HTML
    var htmlString = report.exportDocument(Stimulsoft.Report.StiExportFormat.Html);

    // File System module
    var fs = require('fs');

    // Saving string with rendered report in HTML into a file
    fs.writeFileSync('./SimpleList.html', htmlString);
    console.log("Rendered report saved into HTML-file.");
});

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

Exporting a Report to HTML

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.