agmoyano / node-jasper

JasperReports from Node.js
83 stars 51 forks source link

Error: Could not create class net.sf.jasperreports.engine.data.JsonDataSource #57

Open SrilakshmiGodugunuri7 opened 3 years ago

dcsline commented 3 years ago

This is my tested content for sample.js 👍

dcsline commented 3 years ago

var fs = require('fs');

var jasper = require('node-jasper')({ path: '../lib/jasperreports-5.6.0', reports: { stock_ofertas: { jasper: dirname + '/sample.jasper', jrxml: dirname + '/sample.jrxml', conn: 'in_memory_json' } } });

jasper.ready(function() { var r = jasper.export( { report: 'stock_ofertas', data: { language: 'spanish', // on jasper make a parameter named "dataset2" and use on a subreport: // ((net.sf.jasperreports.engine.data.JsonDataSource)$P{dataset2}) dataset2: jasper.toJsonDataSource( { dados: [{ value: 1, value: 2 }] }, 'dados' ) }, dataset: [ { name: 'Gonzalo', lastname: 'Vinas' // TODO: check on UTF-8 }, { name: 'Agustin', lastname: 'Moyano' } ] }, 'pdf' );

//fs.writeFile(__dirname + '/sample.pdf', r);
fs.writeFile(__dirname+ '/sample.pdf', r, (error)=>{
    if(error) console.log(error);
})

});

leftundersun commented 3 years ago

To make it works, I needed to move the lib folder from dist to root. Sometimes he complains about fonts, but i just changed all to some that works and it goes fine.