This example illustrates how to load the MRT report template, render it and save the result to the MDC 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 should 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(function () {
    console.log("Report rendered. Pages count: ", report.renderedPages.count);

    ...
});

You can save the rendered report using the saveDocumentFile() method, in the arguments of which you need to specify the path to the MDC file of the built document. It is correct to call this method in the callback function after report rendering is complete:
// Renreding report
report.renderAsync(function () {
    ...

    // Saving rendered report to file
    report.saveDocumentFile("SimpleList.mdc");
    console.log("Rendered report saved");
});

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

Loading a Report and Saving a Rendered Report

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.