5 Replies Latest reply on Mar 14, 2008 11:48 AM by damianharvey.damianharvey.gmail.com

    Opening PDF document inside Rich:panel

    sriramsudheer

      Hi folks, I am trying to implement this beautiful example please help me where i am going wrong :(


      The example is working fine for mimetype: image/jpeg but not working for application/pdf
      .xhtml code



       <div class="actionButtons">
                  <h:commandButton id="search" value="Search" action="/UserList.xhtml"/>     
                  <h:commandButton id="runImage" value="Drawing Image" >
                  <a4j:support event="onKeyup" reRender="panelImage"/>
                  </h:commandButton>
                  
                     <h:commandButton id="runReport" value="Drawing PDF" >
                  <a4j:support event="onKeyup" reRender="panelPdf"/>
                  </h:commandButton>                            
              </div>
              
          </h:form>
          <rich:panel id="panelImage">
          <a4j:mediaOutput  element="img" cacheable="false" session="true"
              createContent="#{mediaBean.paint}" mimeType="image/jpeg" />             
           </rich:panel>
           
           <rich:panel id="panelPdf">
          <a4j:mediaOutput  element="object" cacheable="false" session="true"
              createContent="#{reportrunner.paint}" mimeType="application/pdf" />             
           </rich:panel>



      labels.pdf exists in the same folder where seam component exists


      seamComponent:



       public void paint(OutputStream out, Object obj) throws IOException
          {
               log.info("I am trying to display Lables");
                    java.io.InputStream file = 
      
                  FacesContext.getCurrentInstance().
      
                   getExternalContext().
      
                       getResourceAsStream(this.getClass().getClassLoader().getResource("labels.pdf").getFile());
                    
                    if(file== null) {
                         log.info("File Not Found in classpath");
                    }
                    int size = file.available();
                    log.info("size of file:"+size);
                    byte[] pdf = new byte[size];
      
                    file.read(pdf);
      
                    file.close();
      
                    out.write(pdf);
      
               
          }