I am trying to open a pdf from
jsf. Acrobat is opened but it shows error as 'There was an error opening this document. This
file cannot be found.'. When I click the button to open the pdf, it shows 'File Download' window with open, save and cancel
button. After I click Open button, system automatically opens and closes something and then it displays this error message.
Please see below the code.
try {
FacesContext context = FacesContext.getCurrentInstance();
HttpServletResponse response = (HttpServletResponse) context.getExternalContext().getResponse();
response.setHeader("Content-Disposition:", "attachment;filename=test.pdf");
response.setHeader("Cache-Control:", "coderanch,max-age=604800");
response.setContentType("application/pdf");
response.setContentLength(pdf.length);
response.getOutputStream().write(pdf);
context.responseComplete();
}
catch (UnsupportedEncodingException e) {
//TODO Auto-generated catch block
}
catch (IOException e) {
// TODO Auto-generated catch block
}
Instead of Content-Disposition as attachment if I give 'inline', it works but we should open pdf as an attachment not inline.
response.setHeader("Content-Disposition:", "inline;filename=test.pdf");
Could you please provide solution for this.
Thanks,
Sujatha.