Problem exporting to PDF directly

Stimulsoft Reports.JS discussion
Post Reply
agodoo
Posts: 9
Joined: Tue May 22, 2018 10:56 pm

Problem exporting to PDF directly

Post by agodoo »

Hello,
I'm quite new to Stimulsoft and I have an issue.

I followed your sample to export the report to pdf file.

Code: Select all

    report.render();
    var pdfData = report.exportDocument(Stimulsoft.Report.StiExportFormat.Pdf);

    // Get report file name
    var fileName = String.isNullOrEmpty(report.reportAlias) ? report.reportName : report.reportAlias;
    // Save data to file
    Object.saveAs(pdfData, fileName + ".pdf", "application/pdf");
In this way it is asking for choosing the directory where to save the pdf file.
Is there another way to directly save the pdf in a fixed directory, without asking the user to choose it?


kind regards,
Matteo
Edward
Posts: 2913
Joined: Fri Jun 09, 2006 4:02 am

Re: Problem exporting to PDF directly

Post by Edward »

Hi Matteo,

Please check the following approach;
https://www.youtube.com/watch?v=volzOqtESno

https://github.com/stimulsoft/Samples-J ... 20PDF.html

Also, the following page helps to find some good samples as well, we added it to help with a quick start to find some samples easier;
https://www.stimulsoft.com/en/samples
And this one:
https://www.stimulsoft.com/en/videos?tags=js

Thank you,
Edward
agodoo
Posts: 9
Joined: Tue May 22, 2018 10:56 pm

Re: Problem exporting to PDF directly

Post by agodoo »

Hello Edward,
thanks for your additional samples.

I tried to change approach, and changed my code based on another of your samples

Code: Select all

                // Create an PDF settings instance. You can change export settings.
                var settings = new Stimulsoft.Report.Export.StiPdfExportSettings();
                // Create an PDF service instance.
                var service = new Stimulsoft.Report.Export.StiPdfExportService();

                // Create a MemoryStream object.
                var stream = new Stimulsoft.System.IO.MemoryStream();
                // Export PDF using MemoryStream.
                service.exportTo(report, stream, settings);

                // Get PDF data from MemoryStream object
                var data = stream.toArray();
                // Get report file name
                var fileName = String.isNullOrEmpty(report.reportAlias) ? report.reportName : report.reportAlias;
                // Save data to file
                Object.saveAs(data, fileName + ".pdf", "application/pdf");
It works, like already did my previous code, but I have the same issue.
How I can avoid it shows dialog box for choosing path? Is it possible to pass to Object.saveAs the fullname of the file including path, so that it store the file without showing the dialog box? How I can do it?

kind regards,
Matteo
Lech Kulikowski
Posts: 6245
Joined: Tue Mar 20, 2018 5:34 am

Re: Problem exporting to PDF directly

Post by Lech Kulikowski »

Hello,

Unfortunately, on the client side due to the browser limitations, it is not possible.

Thank you.
Post Reply