PDF export in Node with a report accessing databases

Stimulsoft Reports.JS discussion
Post Reply
rafa_ariadna
Posts: 2
Joined: Wed May 10, 2017 3:48 pm

PDF export in Node with a report accessing databases

Post by rafa_ariadna »

Has anyone experimented exporting to PDF in Node with a report that access databases?
The example that Stimultsoft gives, is a report that loads information from a JSON file, but I can't do the same with a report that access databases.
By the way, How can we access in node, attributes like report.dictionary.databases.list or report.dataSources.items? Because I use them to build database connection and sql string, but it seems that node module (stimulsoft-reports-js) doesn't create report object with that attributes.
Thank you.
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

Re: PDF export in Node with a report accessing databases

Post by Alex K. »

Hello,

Please see the following link:
https://www.stimulsoft.com/en/documenta ... tabase.htm

Also, please check the following sample:
https://github.com/stimulsoft/Samples-J ... p%20Server

Thank you.
rafa_ariadna
Posts: 2
Joined: Wed May 10, 2017 3:48 pm

Re: PDF export in Node with a report accessing databases

Post by rafa_ariadna »

Hi Aleksey, thank you for your replay.
In Node there isn't StiOptions.WebServer.url option. I'm talking about a project rendered inside Node not HTML, as the example in https://github.com/stimulsoft/Samples-J ... 20PDF-file but not loading JSON, accessing a database instead.
Thank you.
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

Re: PDF export in Node with a report accessing databases

Post by Alex K. »

Hello,

Yes, please check the following sample which shows how to connect to the database:
https://github.com/stimulsoft/Samples-J ... p%20Server

Thank you.
payoff
Posts: 5
Joined: Fri Jun 09, 2017 10:09 am

Re: PDF export in Node with a report accessing databases

Post by payoff »

Hello,
I've the same issue. I'm trying to generate a pdf in node calling it from a .net core application but the resulting pdf are empty. Here the code
https://gist.github.com/roadrunner75/f3 ... 434afead43

Thanks in advance
Andrea
payoff
Posts: 5
Joined: Fri Jun 09, 2017 10:09 am

Re: PDF export in Node with a report accessing databases

Post by payoff »

I found the way

report.dictionary.databases.clear();
report.dictionary.databases.add(new Stimulsoft.Report.Dictionary.StiPostgreSQLDatabase("BloxSQL", "BloxSQL", connectionString));
report.dictionary.synchronize();

report.renderAsync(function () {


// export to memory stream
var settings = new Stimulsoft.Report.Export.StiPdfExportSettings();
var service = new Stimulsoft.Report.Export.StiPdfExportService();

var stream = new Stimulsoft.System.IO.MemoryStream();

service.exportTo(report, stream, settings);

var data = stream.toArray();

var buffer = new Buffer(data, "utf-8");

// store into a file
var fs = require("fs");

fs.writeFileSync(compiledReportPath, buffer);

callback(/* error */null, "DONE");
});
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

Re: PDF export in Node with a report accessing databases

Post by Alex K. »

Hello

Ok.
Please let us know if you need any additional help.

Thank you.
Post Reply