has anybody gotten reports.js running with nestjs (not NEXTJS)?
I am getting this error
Code: Select all
ReferenceError: document is not defined
at Function.getMeasureDiv (myproj/node_modules/stimulsoft-reports-js/Scripts/stimulsoft.reports.js:14:93378)
at Function.getLineHeightFactor (myproj/node_modules/stimulsoft-reports-js/Scripts/stimulsoft.reports.js:14:95082)
at Function.measureString (myproj/node_modules/stimulsoft-reports-js/Scripts/stimulsoft.reports.js:14:91054)
at Function.measureChars (myproj/node_modules/stimulsoft-reports-js/Scripts/stimulsoft.reports.js:14:92315)
at IY.getFontMetrics (myproj/node_modules/stimulsoft-reports-js/Scripts/stimulsoft.reports.js:59:15719)
at IY.InitFontsData (myproj/node_modules/stimulsoft-reports-js/Scripts/stimulsoft.reports.js:59:21408)
at TY.exportPdf1 (myproj/node_modules/stimulsoft-reports-js/Scripts/stimulsoft.reports.js:58:297182)
at TY.exportTo (myproj/node_modules/stimulsoft-reports-js/Scripts/stimulsoft.reports.js:58:203976)
at Timeout._onTimeout (myproj/node_modules/stimulsoft-reports-js/Scripts/stimulsoft.reports.js:58:204553)
Code: Select all
const generateInvoicePDF = async (x: BizEntity.T) => {
const file = fs.readFileSync("invoice.mrt").toString()
const report = Stimulsoft.Report.StiReport.createNewReport()
report.load(file)
report.dictionary.databases.clear()
const dsinvoice = new Stimulsoft.System.Data.DataSet()
dsinvoice.readJson(x)
report.regData("invoice", "invoice", dsinvoice)
await report.renderAsync(async function () {
await report.exportDocumentAsync(function (data) {
const buffer = Buffer.from(data)
fs.writeFileSync(`result-${x.short_id}.pdf`, buffer)
}, Stimulsoft.Report.StiExportFormat.Pdf)
})
}
Code: Select all
var Stimulsoft = require('stimulsoft-reports-js');
console.log("Stimulsoft Reports loaded");
// Creating new report
var report = new Stimulsoft.Report.StiReport();
console.log("New report created");
// Loading report template
report.loadFile("invoice.mrt");
console.log("Report template loaded");
report.dictionary.databases.clear()
const args = process.argv.slice(2);
// Loading data from JSON file
const x = require(`./invoice-${args}.json`)
const dsinvoice = new Stimulsoft.System.Data.DataSet()
dsinvoice.readJson(x)
report.regData("invoice", "invoice", dsinvoice)
// Renreding report
report.renderAsync(() => {
console.log("Report rendered. Pages count: ", report.renderedPages.count);
// 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 report in PDF into a file
fs.writeFileSync(`./invoice-${args}.pdf`, buffer);
console.log("Rendered report saved into PDF-file.");
}, Stimulsoft.Report.StiExportFormat.Pdf);
});
Thanks for your help
Robert