[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