jcatubay Posted February 7, 2007 Share Posted February 7, 2007 Hi! I have a pdf report that opens when I click a button in my page. But it's not convenient to click back then refresh again if I want to navigate out of the report and continue to navigate throught the page where my button was. Is there a way that I can just open a new browser to display my pdf without navigating away from the page where I click to open the report. Thanks! Link to comment Share on other sites More sharing options...
wegnerk Posted February 7, 2007 Share Posted February 7, 2007 you could set the response like this: Code:response.setContentType("application/pdf");response.addHeader("Content-Disposition", "attachment;filename=report.pdf"); the bold part is the important thing, so you get a popup window which asks if you want to open or save the file. But it opens the pdf in the appropriate application, adobe reader for example. of course you can choose another filename... Don't know, how to open it in a new browser window... are you working with jsp or what? perhaps you could give the button a target="new" or something... hope this helps...Post edited by: wegnerk, at: 2007/02/07 13:39 Link to comment Share on other sites More sharing options...
jcatubay Posted February 8, 2007 Author Share Posted February 8, 2007 Thanks a lot, this works! One more question. Is there a way that I dont have to refresh the page before I can click any buttons or links? Link to comment Share on other sites More sharing options...
marianela Posted February 8, 2007 Share Posted February 8, 2007 Hi jcatubay, My name is marianela and I'm new using ireport and jasperreports. Could you do me a big favor? Please? Could you please share with me the code that you are using to deploy your report? Like I said i'm new here and I really need some code example to do that because the code that I wrote doesn't work at all¡¡¡ Pleaseeeee, I'll really appreciate your help¡¡ Thanks a lot in advanced, have a nice week :) regards,Marianela ;) (in case you you prefer, this is my e-mail: nelis343@hotmail.com) Link to comment Share on other sites More sharing options...
jcatubay Posted February 9, 2007 Author Share Posted February 9, 2007 Here it is.. public void sendToPDF(byte[] bytes){ HttpServletResponse response = (HttpServletResponse) FacesContext.getCurrentInstance().getExternalContext().getResponse(); response.setContentType("application/pdf"); response.addHeader("Content-Disposition","attachment;filename=Report.pdf"); sendToResponse(response, bytes); } private void sendToResponse(HttpServletResponse response, byte[] bytes){ ServletOutputStream servletOutputStream = null; try { servletOutputStream = response.getOutputStream(); response.setContentLength(bytes.length); servletOutputStream.write(bytes, 0, bytes.length); servletOutputStream.flush(); servletOutputStream.close(); } catch (IOException e) { e.printStackTrace(); } FacesContext.getCurrentInstance().responseComplete(); } Link to comment Share on other sites More sharing options...
marianela Posted February 9, 2007 Share Posted February 9, 2007 Thank you so much, I really appreciate yor help... :) I'll try your code. Have a nice weekend, and thanks a lot again. Regards, Marianela;) Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now