Jump to content
We've recently updated our Privacy Statement, available here ×

JRRtfExporter streaming contents to screen


martynhiemstra

Recommended Posts

Hi All,

 

I am using the JRRtfExporter exporter to export a report to a rtf document. At least something that is readable in Word. I can export my report to pdf and excel but wen I use the JRRtfExporter I see this on the screen.

 

{rtf1ansideff0

{fonttbl {f0fnil sansserif;}{f1fnil Arial;}}

{colortbl ;red0green0blue0;red255green255blue255;}

{info{nofpages7}}

etc etc....a long file

 

I am using the following code:

 

JRRtfExporter exporterRTF = new JRRtfExporter ( );

exporterRTF.setParameter ( JRXlsExporterParameter.JASPER_PRINT, jasperPrint );

exporterRTF.setParameter ( JRXlsExporterParameter.OUTPUT_STREAM, response.getOutputStream ( ) );

exporterRTF.exportReport ( );

 

When I use the pdf and excel exporter the browser askes me the question if I want to save or open the file but the JRRtfExporter just streams the contents to the screen.

 

I want the browser to stream the file and not display the contents on the screen so our clients can download the rtf file.

 

Thanks in advance,

Martyn

Link to comment
Share on other sites

  • Replies 3
  • Created
  • Last Reply

Top Posters In This Topic

You need to set the appropriate headers so that the browser recognizes the response type. Try something like

Code:

response.setContentType("application/rtf"«»);
response.setHeader("Content-Disposition", "inline; filename="file.rtf""«»);

 

HTH,

Lucian

Link to comment
Share on other sites

  • 7 months later...

Hi martynhiemstra,

 

Could you pleas paste your code here on how you make a RTF an XLS that could be downloaded by the client?

 

I'm Trying to make this for a few days now, but still don't know how to code it.

 

Thanks in advance.

Link to comment
Share on other sites

Got it!

 

Code:

JRRtfExporter exporter = new JRRtfExporter();
HttpServletResponse response = JSFUtils.getServletResponse();

response.setHeader("Content-disposition", "attachment; filename="+raportName+".rtf"«»);
response.setContentType("application/x-download"«»);

OutputStream outputStream = response.getOutputStream();

HashMap hm = new HashMap();
InputStream reportStream = JSFUtils.getExternalContext().getResourceAsStream(raportTemplate);
JasperPrint jasperPrint = //JasperManager.fillReport(reportStream, hm, appModule.getCurrentConnection());
JasperFillManager.fillReport(reportStream, hm, appModule.getCurrentConnection());
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, outputStream);
exporter.exportReport();
outputStream.flush();
outputStream.close();
JSFUtils.getFacesContext().responseComplete();

 

For XLS use: JRXlsExporter exporterXLS = new JRXlsExporter();

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...