Save PDF Report on Server Side.

Stimulsoft Reports.JS discussion
Post Reply
rjorge99
Posts: 36
Joined: Tue Feb 28, 2023 6:24 pm

Save PDF Report on Server Side.

Post by rjorge99 »

Hi,

I've been reading documentation and other posts, but Im not able to create and save a report on the server side.

I found the next code on other post (Its from 2017)

Client side:

Code: Select all

       
                    var settings = new Stimulsoft.Report.Export.StiPdfExportSettings();
                    var service = new Stimulsoft.Report.Export.StiPdfExportService();
                    var stream = new Stimulsoft.System.IO.MemoryStream();
                    service.exportTo(that.report, stream, settings);
                    var data = stream.toArray();
                    var sendToServer = JSON.stringify(data);
                    
Server Side:

Code: Select all

              
                String[] _reportS = JsonConvert.DeserializeObject<String[]>(sendToServer);
                byte[] _reportB = _reportS.Select(byte.Parse).ToArray();
                File.WriteAllBytes(System.Web.HttpContext.Current.Server.MapPath("~/foo.pdf"), _reportB);

It creates the Pdf, but its emty. I tried this with a report that only has one textbox with some text, thinking that may be the problem was the original report that I was using, but stil having the same problem.

I would appreciate some help

Thanks,
Lech Kulikowski
Posts: 7292
Joined: Tue Mar 20, 2018 5:34 am

Re: Save PDF Report on Server Side.

Post by Lech Kulikowski »

Hello,

Please check the following sample:
https://github.com/stimulsoft/Samples-R ... 20to%20PDF

Thank you.
rjorge99
Posts: 36
Joined: Tue Feb 28, 2023 6:24 pm

Re: Save PDF Report on Server Side.

Post by rjorge99 »

Hi,

Thanks for the answer.

We are working with asp.net on the back end. So I would need, based on the example I found (my first post), to send that to the server, and use C # to write that to disk.

I checked the example you mentioned, and looks like that example is for the use of Node for the back end.

Thanks.
Lech Kulikowski
Posts: 7292
Joined: Tue Mar 20, 2018 5:34 am

Re: Save PDF Report on Server Side.

Post by Lech Kulikowski »

Hello,

Please check the following code:
https://github.com/stimulsoft/Samples-R ... rom%20Code

Thank you.
rjorge99
Posts: 36
Joined: Tue Feb 28, 2023 6:24 pm

Re: Save PDF Report on Server Side.

Post by rjorge99 »

Hi,

May be Im not explaining myself.

The product we bought is the Reports.js, and works great, but we have a flow where we need to save the report to a specific location in the Server, using the backend (Asp.net).

The sample I found using Reports.js is to export the report to stream and serialize that stream , so I can send it to the backend,

Code: Select all

 var settings = new Stimulsoft.Report.Export.StiPdfExportSettings();
                    var service = new Stimulsoft.Report.Export.StiPdfExportService();
                    var stream = new Stimulsoft.System.IO.MemoryStream();
                    service.exportTo(that.report, stream, settings);
                    var data = stream.toArray();
                    var sendToServer = JSON.stringify(data);
and on the backend take that serialized information, deserialized and then write it to disk.

Code: Select all

String[] _reportS = JsonConvert.DeserializeObject<String[]>(sendToServer);
                byte[] _reportB = _reportS.Select(byte.Parse).ToArray();
                File.WriteAllBytes(System.Web.HttpContext.Current.Server.MapPath("~/foo.pdf"), _reportB);

Again, the product that my company bought is Reports.JS.

The last samples you provieded, assumes we have Reports.Web, which we dont have, we bought the licence for Reports.JS.


Thanks
Lech Kulikowski
Posts: 7292
Joined: Tue Mar 20, 2018 5:34 am

Re: Save PDF Report on Server Side.

Post by Lech Kulikowski »

Hello,

For exporting reports on the backend you need touse the server side, for example, Node.JS.

Thank you.
rjorge99
Posts: 36
Joined: Tue Feb 28, 2023 6:24 pm

Re: Save PDF Report on Server Side.

Post by rjorge99 »

I just found out that the code that other people used before using Reports.JS works great, the part I was missing was to render the report.

Code: Select all

	var report = new Stimulsoft.Report.StiReport();
	report.loadFile("../reports/SimpleList.mrt");
	report.renderAsync(function() {
		    var settings = new Stimulsoft.Report.Export.StiPdfExportSettings();
                    var service = new Stimulsoft.Report.Export.StiPdfExportService();
                    var stream = new Stimulsoft.System.IO.MemoryStream();
                    service.exportTo(that.report, stream, settings);
                    var data = stream.toArray();
                    var sendToServer = JSON.stringify(data);
	})	
Server side:

Code: Select all

		String[] _reportS = JsonConvert.DeserializeObject<String[]>(sendToServer);
                byte[] _reportB = _reportS.Select(byte.Parse).ToArray();
                File.WriteAllBytes(System.Web.HttpContext.Current.Server.MapPath("~/foo.pdf"), _reportB);
Lech Kulikowski
Posts: 7292
Joined: Tue Mar 20, 2018 5:34 am

Re: Save PDF Report on Server Side.

Post by Lech Kulikowski »

Hello,

Thank you for the information.
Post Reply