Jump to content
We've recently updated our Privacy Statement, available here ×

Open new browser for the report!


jcatubay

Recommended Posts

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

  • Replies 5
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

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

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

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...