Page 1 of 1
Generate PDF without downloading it (upload to server)
Posted: Fri Dec 04, 2020 11:06 am
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.
Re: Generate PDF without downloading it (upload to server)
Posted: Sat Dec 05, 2020 9:27 am
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.
Re: Generate PDF without downloading it (upload to server)
Posted: Tue Dec 08, 2020 10:36 am
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" });
});
Re: Generate PDF without downloading it (upload to server)
Posted: Tue Dec 08, 2020 12:38 pm
by HighAley
Hello,
Thank you for sharing your solution.