agmoyano / node-jasper

JasperReports from Node.js
84 stars 52 forks source link

how to choose jasper file in var report #44

Closed naphattharawat closed 5 years ago

naphattharawat commented 5 years ago

app.get('/pdf', function (req, res, next) {

var report = {
    report: 'name',

// file: xxx.jasper };

var pdf = jasper.pdf(report);
console.log(pdf);

res.set({
    'Content-type': 'application/pdf',
    'Content-Length': pdf.length
});
res.send(pdf);

});

agmoyano commented 5 years ago

A report definition is an object of type

{ jasper: // path to jasper file jrxml: // path to jrxml file conn: //connection name or definition }

One of jasper or jrxml must be present.

If that definition is made in general configuration options, you must name it, and you can use it like

jasper.pdf('name')

If you didn't define it in general options, you can still get the PDF by

jasper.pdf({ jasper: '/path/to/jasper/file', conn: 'connection name' })

Hope that cleared things.

Happy coding!

agmoyano commented 5 years ago

Forgot to mention, if you need to specify data, you can get PDF like this

jasper.pdf({ report: { jasper: '/path/to/jasper/file', conn: 'connection name' }, data: {} //data to pass to the report })

Cheers