Page 1 of 1

Running on NESTJS

Posted: Mon Oct 21, 2024 3:34 pm
by robkuz
Hi,

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)
with the following code (Typescript)

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)
    })
}
If I however use this code using the same mrt-file in pure nodejs with JS

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);
});
Then the reports are generated as asked for

Thanks for your help

Robert

Re: Running on NESTJS

Posted: Mon Oct 21, 2024 4:39 pm
by Lech Kulikowski

Re: Running on NESTJS

Posted: Mon Oct 21, 2024 5:05 pm
by robkuz
I did check those. How should that help?

Re: Running on NESTJS

Posted: Tue Oct 22, 2024 8:34 am
by Lech Kulikowski
Hello,

How do you connect scripts to a project that doesn't work?

import { Stimulsoft } from 'stimulsoft-reports-js/Scripts/stimulsoft.viewer';
should specify the full path to scripts, not to the nmp module.

Thank you.

Re: Running on NESTJS

Posted: Tue Oct 22, 2024 12:54 pm
by robkuz
Hi,

sorry but either ou dont understand my problem or I dont understand your answer.

Lets try again

a) I dont want to SHOW anything via the viewer therefore I do not need to import any scripts
b) I just want to merge data with an existing template file and generate a PDF from that
c) I can get a very simplified version of (b) running within a pure nodejs/javascript environment
d) as soon as I port that simplified version into my nestjs environment with typescript I get the error message above

Re: Running on NESTJS

Posted: Wed Oct 23, 2024 11:48 am
by Lech Kulikowski
Hello,

Please send us a sample project that reproduces the issue for analysis.

Thank you.