Generate PDF without downloading it (upload to server)

Stimulsoft Reports.JS discussion
Post Reply
csrt
Posts: 61
Joined: Thu Jan 17, 2019 12:38 pm

Generate PDF without downloading it (upload to server)

Post by csrt »

Hello.
I'm trying to generate a PDF from a report, to eventually upload it to a server.
I am using the method Stimulsoft.System.StiObject.saveAs(data, filename + ".pdf", "application/pdf");, but the problem is that the generated PDF is downloaded to local machine.

Is there any method to generate the PDF in code, so that it would eventually be uploaded to a server as a file?
Thank you.
Lech Kulikowski
Posts: 7292
Joined: Tue Mar 20, 2018 5:34 am

Re: Generate PDF without downloading it (upload to server)

Post by Lech Kulikowski »

Hello,

In that case, you should export report on the server side, for example - node.js
https://github.com/stimulsoft/Samples-J ... 20PDF-file

Thank you.
csrt
Posts: 61
Joined: Thu Jan 17, 2019 12:38 pm

Re: Generate PDF without downloading it (upload to server)

Post by csrt »

Hello. I've managed to solve it by making a BLOB and a FILE from the array stream.
In case someone needs it:

Code: Select all

var report = new $window.Stimulsoft.Report.StiReport();
                report.load(scope.reportFile.toJSON());

                var dataSet = new $window.Stimulsoft.System.Data.DataSet("SimpleDataSet");
                dataSet.readJson({ root: data });

                var filename = attr.filename || "document"; // custom filename (if such)
                report.regData(dataSet.dataSetName, "", dataSet);

                report.renderAsync(function() {
                    var settings = new $window.Stimulsoft.Report.Export.StiPdfExportSettings();
                    var service = new $window.Stimulsoft.Report.Export.StiPdfExportService();
                    var stream = new $window.Stimulsoft.System.IO.MemoryStream();
                    service.exportTo(report, stream, settings);
                    var data = stream.toArray();

                    // making a file from Stimulsoft Stream
                    var blob = new Blob([new Uint8Array(data)], { type: "application/pdf" });
                    var resultFile = new File([blob], filename + ".pdf", { type: "application/pdf" });
                });
HighAley
Posts: 8430
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: Generate PDF without downloading it (upload to server)

Post by HighAley »

Hello,

Thank you for sharing your solution.
Post Reply