Page 1 of 1

Save PDF Report on Server Side.

Posted: Mon Sep 30, 2024 9:04 pm
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,

Re: Save PDF Report on Server Side.

Posted: Tue Oct 01, 2024 7:23 am
by Lech Kulikowski
Hello,

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

Thank you.

Re: Save PDF Report on Server Side.

Posted: Wed Oct 02, 2024 7:00 pm
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.

Re: Save PDF Report on Server Side.

Posted: Wed Oct 02, 2024 10:48 pm
by Lech Kulikowski
Hello,

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

Thank you.

Re: Save PDF Report on Server Side.

Posted: Thu Oct 03, 2024 2:44 pm
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

Re: Save PDF Report on Server Side.

Posted: Thu Oct 03, 2024 11:16 pm
by Lech Kulikowski
Hello,

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

Thank you.

Re: Save PDF Report on Server Side.

Posted: Fri Oct 04, 2024 5:37 pm
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);

Re: Save PDF Report on Server Side.

Posted: Mon Oct 07, 2024 7:48 am
by Lech Kulikowski
Hello,

Thank you for the information.