Export Report without opening Viewer in web application

Stimulsoft Reports.JAVA discussion
Post Reply
prakashn
Posts: 6
Joined: Tue Jan 28, 2014 6:37 am

Export Report without opening Viewer in web application

Post by prakashn »

Hi Team,

We integrated Stimulsoft Reports.Fx for Java with our web application and generating reports.

Now we got new requirement like, need to directly export the report to PDF or Excle without opening the viewer or at runtime we need to disable/hide few export options from viewer.

Please let me know how can we achieve this. Its a bit urgent requirement.

Thanks in advance.

Regards,
Prakash
HighAley
Posts: 8431
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: Export Report without opening Viewer in web application

Post by HighAley »

Hello.

Sorry for the delay with answer.
We need some additional time to prepare answer for you.

Thank you.
Vadim
Posts: 363
Joined: Tue Apr 23, 2013 11:23 am

Re: Export Report without opening Viewer in web application

Post by Vadim »

Hello.
For direct open file in browser you can use servlet that generate with custom settings & return file (example for PDF file):

Code: Select all

protected void doGet(HttpServletRequest request, HttpServletResponse response) {
try {
            StiDocument document = StiSerializeManager.deserializeDocument(new File(
                    "c:\\TwoSimpleLists.mdc"));
            response.setContentType("application/pdf");
            StiPdfExportSettings settings = new StiPdfExportSettings();
            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            StiExportManager.exportPdf(document.getReport(), settings, bos);
            byte[] binaryData = bos.toByteArray();
            response.addHeader("Content-Length", String.valueOf(binaryData.length));
            //response.addHeader("Content-Disposition", "attachment;filename=\"test.pdf\""); uncomment it if you don't want to open file in browser - want to download it
            StiIOUtil.writeInputStream(response.getOutputStream(), new ByteArrayInputStream(
                    binaryData));
        } catch (Exception e) {
            e.printStackTrace();
        }
}
prakashn
Posts: 6
Joined: Tue Jan 28, 2014 6:37 am

Re: Export Report without opening Viewer in web application

Post by prakashn »

Hi Vadim,

This is working fine for .mdc files. But for .mrt files, the response is null and returns corrupt file.

Is there some other way for .mrt files?

Thanks,
Prakash
Vadim
Posts: 363
Joined: Tue Apr 23, 2013 11:23 am

Re: Export Report without opening Viewer in web application

Post by Vadim »

Hello.
You must render .mrt file (see our Samples forlder), for example:

Code: Select all

StiReport renderReport = StiSerializeManager.deserializeReport(new File("Reports/SimpleList.mrt"));
//add neccessary databases
renderReport.getDictionary().getDatabases().add(new StiXmlDatabase("Demo", "Demo.xsd", "Demo.xml"));
//render report
renderReport.Render(false);
than you can use rendered report.
prakashn wrote:Hi Vadim,

This is working fine for .mdc files. But for .mrt files, the response is null and returns corrupt file.

Is there some other way for .mrt files?

Thanks,
Prakash
prakashn
Posts: 6
Joined: Tue Jan 28, 2014 6:37 am

Re: Export Report without opening Viewer in web application

Post by prakashn »

Thanks Vadim. Its working fine now.
Andrew
Posts: 4107
Joined: Fri Jun 09, 2006 3:58 am

Re: Export Report without opening Viewer in web application

Post by Andrew »

Great!

Thank you.
Post Reply