6 Replies Latest reply on Mar 19, 2008 5:16 AM by Richard Stanford

    PDF in all the browsers

    Vemula sriramsudheer Newbie

      HI all, I am creating PDF's using BIRT reports, I need to show 3 reports in same page. I tried the following tags: rich:mediaoutput (Lot of posts in jboss site but no one posted successful story)


      iframe


      Object, In jsp it is possible to use object tag but i am using JSF and .xhtml so i dont actually know how exactly to use this.


      One more thing to that i cant actually save pdf to harddisk. So is there a way to show the bytestream as pdf in browser.


      This is my sceniario and i need a feasible solution if possible.

        • 1. Re: PDF in all the browsers
          Nicklas Karlsson Master

          What keeps you from saving the PDF to the disk?

          • 2. Re: PDF in all the browsers
            Vemula sriramsudheer Newbie

            Hi Nicklas,


                       From my requirement perspective i cant store the reports generated by Birt. I have to show it to the user through browser on fly. Actually i have to show multiple pdfs at the same time on fly in same page
                        

            • 3. Re: PDF in all the browsers
              Nicklas Karlsson Master

              Never tried it but I'd be surprised if you couldn't get a byte[] when rendering with the API. Can you merge them into one or do they have to be in separate frames etc?

              • 4. Re: PDF in all the browsers
                Vemula sriramsudheer Newbie

                Hi Nicklas,
                           I need to show PDF's seperately what i mean is i will generate 3 reports at the same time show them all in different frames in a single page

                • 5. Re: PDF in all the browsers
                  Richard Stanford Newbie

                  What you can do then is first, create a new page with three frames.  Then when that page renders on the browser, it will request each document separately - making that part of the requirement a non-event.


                  As far as pushing the PDFs out as files, the cleanest way I've found is to use a RESTful approach.  Then, when the file is requested, push it out as a byte array with something similar to this:



                       public void sendFile(byte[] file, String contentType, String filename) throws IOException {
                            if (file == null) {
                                 return;
                            }
                            FacesContext fc = FacesContext.getCurrentInstance();
                            HttpServletResponse servletResponse = (HttpServletResponse) fc.getExternalContext().getResponse();
                            if (filename != null) {
                                 servletResponse.setHeader("Content-disposition", "attachment; filename=" + filename);
                            }
                            if (contentType != null) {
                                 servletResponse.setContentType(contentType);
                            }
                            ServletOutputStream os = servletResponse.getOutputStream();
                            os.write(file);
                            fc.responseComplete();
                       }



                  If you don't specify a filename, it will generally be rendered in line (depending on browser settings, of course).

                  • 6. Re: PDF in all the browsers
                    Richard Stanford Newbie

                    BTW, all you need to do to access it is to use a url such as /.../report.pdf?reportParam=2 for the 2nd frame, and something like this in your pages.xml:


                    <page view-id="/report.xhtml" action="#{fileRender.sendFile(someBean.pdf, 'application/pdf')}">
                            <param name="reportParam" value="#{someBean.reportId}"/>
                    </page>



                    And yes, I didn't show a convenience method in the fileRender bean that passes a null for the filename :)  I've taken to using this approach for any binary files that need to be outputted - so many times I ran into problems with any of the JSF binary rendering tags I used.