-
1. Re: PDF in all the browsers
nickarls Mar 18, 2008 6:23 AM (in response to sriramsudheer)What keeps you from saving the PDF to the disk?
-
2. Re: PDF in all the browsers
sriramsudheer Mar 18, 2008 6:45 AM (in response to sriramsudheer)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
nickarls Mar 18, 2008 7:30 AM (in response to sriramsudheer)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
sriramsudheer Mar 19, 2008 12:00 AM (in response to sriramsudheer)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
richard1 Mar 19, 2008 5:09 AM (in response to sriramsudheer)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
richard1 Mar 19, 2008 5:16 AM (in response to sriramsudheer)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.