You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Le Van <lv...@it.fts-vn.com> on 2006/03/27 17:06:08 UTC

PDF Problems with IE

 I have the problem about displaying PDF file ( Pdf file got from  
binary stream of pdf file).
At First.jsp
<t:commandButton value="#{myBean.getPDF}"/>
MyBean.java
public String getPDF() {
  HttpServletResponse response = 
(HttpServletResponse)getExternalContext().getResponse();
            Blob myBlob = getData();      // getDate connect database to 
get an Blob object.
            if ( myBlob != null ){     
            response.setContentType("application/pdf");
            OutputStream out = response.getOutputStream();
            int iLen = (int)myBlob.length();         
           
            ByteArrayOutputStream output = new ByteArrayOutputStream(iLen);
            output.write(myBlob.getBytes(1, iLen), 0, iLen);
            response.setContentLength(output.size());           
            out.write(output.toByteArray());
            out.close();           
            FacesContext.getCurrentInstance().responseComplete();
            return null;
}
when I click on button to get pdf, pdf file will display on IE browser.( 
Don't pop up Open/Save File Dialog).
The  problem is i want to hide address bar and title bar ( I can hide 
address bar, but the title bar always show 
"http://localhost:7001/myApp/First.faces"). But with above code I can't 
hide title bar. So I port code by using jsp file to get pdf.
<%@page import="javax.faces.context.*"%>
<%@page import="javax.faces.el.*"%>
<%@page import="javax.servlet.ServletOutputStream;"%>
<%@page import="van.MyBean%>
<%@page import="java.io.*;" %>
<%@page import="javax.servlet.http.HttpServletResponse;"%>   
<HTML>
<HEAD>   
<META HTTP-EQUIV="Accept-Ranges" CONTENT="bytes">
</HEAD>
<BODY>
    <%   
        FacesContext context = FacesContext.getCurrentInstance();
        ExternalContext ec = context.getExternalContext();
        ValueBinding binding = 
(ValueBinding)context.getApplication().createValueBinding("#{myBean}");
        MyBean bean= (MyBean)binding.getValue(context);
         HttpServletResponse response2 = 
(HttpServletResponse)ec.getResponse();
        response2.setContentType("application/pdf");
         ServletOutputStream stream = response2.getOutputStream();         
        if(bean!=null) {               
            byte[] byteArray = null;
            byteArray = bean.getData();
            int l = byteArray.length;
            response2.setContentLength(l);
            if(byteArray!=null)
            {
                stream.write(byteArray,0,l);           
            }
            stream.close();
        }    
    
    %>
</BODY>
</HTML>
Oppps, if I using jsp instead of using bean and call action, IE can't 
display . It just display binary data, byte and byte. If I add
response.addHeader("Content-Disposition", "attachment; filename="     + 
"van.pdf");
IE pop up open/save dialog, and everything is ok.
I can summary the problem:
+ I want to hide the title bar (just display title not url of jsp file).
+ how can i display pdf in IE browser when we open a url. ( not open 
from pop up dialog). Note that Firefox is OK, Firefox always know 
content-type header while IE just know file extension (.pdf).
+ I don't know why I call action from bean, pdf can show in IE but jsp 
file don't.
Anyone can help me ???
Thanks and best regards
Van