  | Mailing List | | Home | | Forum Home | | JBoss - Java Application Server | | Tomcat - JSP/Servlet container | | Struts - A MVC web framework | | iText - An open source PDF Java Library | | JDOM - JDOM XML Parser | | JSP - A mailing list about Java Server Pages specification and reference | | J2EE - A mailing list for Java(tm) 2 Platform, Enterprise Edition | | J2EE Pattern - An interest list for Sun Java Center J2EE Pattern Catalog | | Servlet - A mailing list for discussion about Sun Microsystem's Java Servlet API Technology | |
Struts & Hibernate
|
|
|
  | | | Streaming PDF from servlet problem | Streaming PDF from servlet problem 2007-11-07 - By Ismael F
Back
Yes it looks strange! But what type of content-type are you passing as a parameter? "application/octet-stream", or "application/pdf"? And what about the file name (downloadFileName)? Try something like "******* .pdf" Well I hope It can help. Ismael. > Date: Tue, 6 Nov 2007 08:19:08 -0800> From: leboldusj@(protected)> To: itext -questions@(protected)> Subject: [iText-questions] Streaming PDF from servlet problem> > > Strange problem, I use the following method to stream a pdf to a browser> > private void streamToDownload(HttpServletResponse response, > ByteArrayOutputStream baos, String contentType,> String downloadFileName) throws ServletException> {> try> {> ServletOutputStream servletOutputStream => response.getOutputStream();> byte[] bytes = baos.toByteArray();> servletOutputStream.write(bytes, 0, bytes.length);> response.setContentType (contentType);> response.setHeader("content-disposition", "attachment;> filename =" + downloadFileName);> response.setContentLength(bytes.length);> servletOutputStream.flush();> servletOutputStream.close();> }> catch (IOException e)> {> throw new ServletException(e);> }> }> > > It works fine, the user is prompted to save or open the file in the default> application.> > However; this is the weird part, as soon as an image is added to the PDF, or> another PDF is used as a background for the PDF created with iText, the pdf> opens in the browser, not at all the behaviour I want.> > Is there something about images or PDFs that "over rides" the content> dispostion? That doesn't make sense, but if I had an explantion for this> behaviour I wouldn't be posting here right?> > Thanks for any help> > -- > View this message in context : http://www.nabble.com/Streaming-PDF-from-servlet-problem-tf4759225.html #a13610196> Sent from the iText - General mailing list archive at Nabble.com.> > > -- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- -----> This SF.net email is sponsored by: Splunk Inc.> Still grepping through log files to find problems? Stop.> Now Search log events and configuration files using AJAX and a browser.> Download your FREE copy of Splunk now >> http://get .splunk.com/> __ ____ ____ ____ ____ ____ ____ ____ ____ ____> iText-questions mailing list> iText-questions@(protected)> https://lists.sourceforge .net/lists/listinfo/itext-questions> Buy the iText book: http://itext.ugent.be /itext-in-action/ __ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ __ Express yourself instantly with MSN Messenger! Download today it's FREE! http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/ <html> <head> <style> .hmmessage P { margin:0px; padding:0px } body.hmmessage { FONT-SIZE: 10pt; FONT-FAMILY:Tahoma } </style> </head> <body class='hmmessage'> Yes it looks strange!<BR> <BR> But what type of content-type are you passing as a parameter? <FONT color= #2a00ff size=2><BR> "application/octet-stream", or "<FONT color=#2a00ff size=2>application/pdf"?< /FONT><BR> <FONT color=#2a00ff size=2></FONT> <BR> <FONT color=#2a00ff size=2>And what about the file name (downloadFileName)? Try something like "*******.pdf"</FONT><BR> <BR> Well I hope It can help.<BR> </FONT> <BR> Ismael.<BR> <BR><BR>> Date: Tue, 6 Nov 2007 08:19:08 -0800<BR>> From: leboldusj@(protected) .com<BR>> To: itext-questions@(protected)<BR>> Subject: [iText -questions] Streaming PDF from servlet problem<BR>> <BR>> <BR>> Strange problem, I use the following method to stream a pdf to a browser<BR>> <BR> > private void streamToDownload(HttpServletResponse response,<BR>> ByteArrayOutputStream baos, String contentType,<BR>> String downloadFileName ) throws ServletException<BR>> {<BR>> try<BR>> {<BR>> ServletOutputStream servletOutputStream =<BR>> response.getOutputStream(); <BR>> byte[] bytes = baos.toByteArray();<BR>> servletOutputStream.write (bytes, 0, bytes.length);<BR>> response.setContentType(contentType);<BR>> response.setHeader("content-disposition", "attachment;<BR>> filename=" + downloadFileName);<BR>> response.setContentLength(bytes.length);<BR>> servletOutputStream.flush();<BR>> servletOutputStream.close();<BR>> }<BR> > catch (IOException e)<BR>> {<BR>> throw new ServletException(e);<BR> > }<BR>> }<BR>> <BR>> <BR>> It works fine, the user is prompted to save or open the file in the default<BR>> application.<BR>> <BR>> However; this is the weird part, as soon as an image is added to the PDF, or<BR >> another PDF is used as a background for the PDF created with iText, the pdf<BR>> opens in the browser, not at all the behaviour I want.<BR>> <BR> > Is there something about images or PDFs that "over rides" the content<BR> > dispostion? That doesn't make sense, but if I had an explantion for this<BR >> behaviour I wouldn't be posting here right?<BR>> <BR>> Thanks for any help<BR>> <BR>> -- <BR>> View this message in context: http://www .nabble.com/Streaming-PDF-from-servlet-problem-tf4759225.html#a13610196<BR>> Sent from the iText - General mailing list archive at Nabble.com.<BR>> <BR> > <BR>> -- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- --- -- ----<BR>> This SF.net email is sponsored by: Splunk Inc.<BR>> Still grepping through log files to find problems? Stop.<BR>> Now Search log events and configuration files using AJAX and a browser.<BR>> Download your FREE copy of Splunk now >> http://get.splunk.com/<BR>> __ ____ ____ __ __ ____ ____ ____ ____ ____ ____<BR>> iText-questions mailing list<BR>> iText-questions@(protected)<BR>> https://lists.sourceforge.net /lists/listinfo/itext-questions<BR>> Buy the iText book: http://itext.ugent .be/itext-in-action/<BR><BR><br /><hr />Express yourself instantly with MSN Messenger! <a href='http://clk.atdmt.com/AVE/go/onm00200471ave/direct/01/' target='_new'>MSN Messenger</a></body> </html> -- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----- This SF.net email is sponsored by: Splunk Inc. Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/ __ ____ ____ ____ ____ ____ ____ ____ ____ ____ iText-questions mailing list iText-questions@(protected) https://lists.sourceforge.net/lists/listinfo/itext-questions Buy the iText book: http://itext.ugent.be/itext-in-action/
|
|
 |