3 Replies Latest reply on Jun 17, 2008 11:19 AM by Marine Wacheux

    a4j:mediaOutput to display a PDF

    Marine Wacheux Newbie

      Hi,

      I'm trying to display a PDF file within a page, using a4j:mediaOutput component to render "object" tag (with Firefox).
      HTML tag is rendered correctly, but as other people I read in many posts, the PDF doesn't display. I only see that space is reserved, but empty.

      Someone said (http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4038990#4038990) in reply of a reported issue (http://jira.jboss.com/jira/browse/AJSF-34) that we have to use "classid" attribute, but I did a simple test (as someone else in another post) that work without classid. Both following examples work in a static HTML page :

      <object data="doc1.pdf" style="width:300px; height:300px;" type="application/pdf"></object>
      <object data="doc1" style="width:300px; height:300px;" type="application/pdf"></object>


      Is there or not, a way to do that with a4j:mediaOutput component ?

      Thanks for any help.
      Marine

      Code of my test with A4J :

      <a4j:mediaOutput id="docPdf"
       createContent="#{myBean.afficherPDF}"
       element="object" cacheable="false" value="test.pdf" session="true"
       mimeType="application/pdf" type="application/pdf"
       style="width:300px; height:300px;"/>
      


      public void afficherPDF(OutputStream os, Object obj) {
       Fichier f = null;
       try {
      
       f = docService.genererFichierPourImpression();
       os.write(f.getContenu());
       //os.flush();
      
       } catch (IOException e) {
       log.error("Erreur lors de la generation du PDF", e);
       }
       }
       }



      In HTML rendered source :

      <object id="body:formRedactionDocumentSimple:docPdf" data="/gcm-web-patients/faces/a4j_3_1_4.GAorg.ajax4jsf.resource.UserResource/n/s/-1248334925/DATA/eAFVkc9KA(...)Qrqj4_" style="width:300px; height:300px;"></object>



      But if I look source code with Firebug extension, I see :

      <object id="body:formRedactionDocumentSimple:docPdf" style="width: 300px; height: 300px;" data="/gcm-web-patients/faces/a4j_3_1_4.GAorg.ajax4jsf.resource.UserResource/n/s/-1248334925/DATA/eAFVkc9KA(...)Qrqj4_" type="application/pdf"/>


        • 1. Re: a4j:mediaOutput to display a PDF
          Vemula sriramsudheer Newbie

          Hi marine,
          I am also stuck at the same point and if you able to find a solution please help me by posting your answer and where went wrong.

          • 2. Re: a4j:mediaOutput to display a PDF
            Adam Wells Newbie

            I had the same problem, and a quick look around this forum has no success stories.

            I found a solution http://www.seamframework.org/Community/DirectPDFServing#comment8459 that works very well for me.

            I use this in pages.xml

             <page view-id="/secure/billing/pdfInvoice.xhtml" action="#{billingDataProvider.outputPdf}">
             <param name="pdfInvoiceUid" value="#{billingDataProvider.pdfInvoiceUid}"/>
             </page>
            


            and my bean has this method:

             public void outputPdf() {
             PDFInvoiceDTO invoice = pdfInvoicingService.getInvoice(pdfInvoiceUid);
            
             final HttpServletResponse response = (HttpServletResponse) facesContext.getExternalContext().getResponse();
             response.setContentType("application/pdf");
             response.setHeader("Content-Disposition", " attachment; filename=invoice.pdf");
            
             try {
             response.getOutputStream().write(invoice.getInvoiceDocument());
             } catch (IOException e) {
             // TODO Auto-generated catch block
             e.printStackTrace();
             }
             facesContext.responseComplete();
            
             }
            
            


            Hope this helps...

            • 3. Re: a4j:mediaOutput to display a PDF
              Marine Wacheux Newbie

              Thanks for your reply. But If I understand well your solution, it renders the PDF file directly in the navigator, and not inside an HTML "object", inside a webpage with others HTML elements.
              Here is an example of how I would like to display the PDF file :

              <html>
              <head>(...)</head>
              
              <body>
              
              Here is the resulting document :
              
              <object data="myDoc.pdf" style="width:300px; height:300px;" type="application/pdf">
              </object>
              
              I can write some text in my page, around the object that display the PDF file....
              
              </body>
              </html>