[jboss-user] [JBoss Portal] - How to stream a pdf at portlet?

littleprince do-not-reply at jboss.com
Tue Mar 4 22:38:17 EST 2008


i want to stream a pdf report to a page, but some how i got funny character when streaming. below is the code i wrote. i got this works at normal java application, but not in portlet.

FacesContext ctx=FacesContext.getCurrentInstance();
String fullPath = getReportPath(reportName);
HttpServletResponse response=(HttpServletResponse)ctx.getExternalContext().getResponse();
response.setContentType("application/pdf");
response.addHeader("Content-Disposition", "attachment; filename="+reportName+".pdf");
JasperPrint jasperPrint=JasperFillManager.fillReport(fullPath, parameters, new JRBeanCollectionDataSource(list));
JasperExportManager.exportReportToPdfStream(jasperPrint, response.getOutputStream());
	    	
ctx.getApplication().getStateManager().saveSerializedView(ctx); 
ctx.responseComplete();

the result i got is 
%PDF-1.4 %âãÏÓ 4 0 obj <>stream xœ¥˜ÉnÛ0†ïz 
ÓCenZœ[‚.hö¸§¢Ò]q
Øúú¥š
†ÑŒ$$±Âd>Íð*óǒ}MîW‰`Ü|4¯¥–luHŸæ»mrónõ'ùè‡p¶9ø2”iރ’ ހ¼ýõi—ÜܽTû {¬×§ÍoöP?O—榜í"7þùË\«ð§<-™ýzø –&ƒ`ÿ,§+Ê%“Š½;ÕÉ=(U±¢ÈJý~Lß.§™KÔ1¦ÃÂ
Ó"k’¦2c‡$Ó͵_>%4ª_¢¹ TvÍÂÂ
Q ¤5Sò¬½7ËtTò¬@$ÿ°¾Ôc57[ðÕ|I=Àú%A>_t› Ã`Q1n¦îÂ(Ù _DÂÂ
æù
V~µ?ŒV¾Ù>/HÒ¿âú5EE ~Ÿå@]1n®úy9¨~ÁõœëûRn€Ùˆ/¤”­g×!ýØ|ëŠq3 eÞ6`™G e‰4ànsÙÿŽÕ¿ÙøË-%Iÿ³kŠŽ¾þ6:*@]1nî¤53¶Ñ_ˆ7fm›m¨ߎÕËÓè¿@ÍF|!µÊi7àìš"¤ß

However, if i use 
JasperExportManager.exportReportToPdfFile(jasperPrint,"c:\\test.pdf");
i got the pdf nicely, but it save into my local, which does not serve my need.

So what is the correct way to stream a pdf? i want to do it like a popup message to let me download the pdf.

Thanks in advance. 
			

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4134107#4134107

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4134107




More information about the jboss-user mailing list