This example shows how to supply custom headers for JSON Database. First, create the new dashboard:
// Creating new dashboard
var report = Stimulsoft.Report.StiReport.createNewDashboard();
console.log("New dashboard created");
...
Then, in
onBeginProcessData
event handler add custom HTTP headers:
...
// In `onBeginProcessData` event handler add custom HTTP headers
report.onBeginProcessData = function (args) {
if (
args.database === "JSON" &&
args.command === "GetData" &&
args.pathData && args.pathData.endsWith("/ProtectedDemo.json")
) {
// Add custom header to pass through server protection
args.headers.push({key: "X-Auth-Token", value: "*YOUR TOKEN*"});
}
};
...
After that, load dashboard template and export it to PDF:
...
// Loading dashboard template
report.loadFile("DBSsimp.mrt");
console.log("Dashboard template loaded");
// Export to PDF
report.exportDocumentAsync((pdfData) => {
// Converting Array into buffer
var buffer = Buffer.from(pdfData);
// File System module
var fs = require('fs');
// Saving string with rendered dashboard in PDF into a file
fs.writeFileSync('./Dashboard.pdf', buffer);
console.log("Dashboard saved into PDF-file.");
}, Stimulsoft.Report.StiExportFormat.Pdf);
In the screenshot below you can see the result of the sample code: