• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

When i try to open pdf, it shows 'There was an error opening this document.' message

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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:", "public,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.
 
Saloon Keeper
Posts: 27762
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the JavaRanch!

I think what you're describing is a bug with Acrobat on a certain browser/OS. At least it sounds familiar. If that's true, there's nothing you can do about it. The cure was to have the user download the file and then open the downloaded copy.

The problem seems to be that the attachment went into the temporary downloads directory, but Acrobat was looking either for a different name or a different location, I'm not sure which.
 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, it sounds like relating to Acrobat/MSIE bug. The bug is caused by having spaces in the temporaty folder (like for example TMP="C:\Documents and Settings\User\Temp". The downloaded file is stored in that folder and passed to the acrobat executable in not quoted form, like this:
acrobat.exe C:\Documents and Settings\User\Temp\file.pdf

Invoked with such a command acrobat thinks it was passed 3 separate arguments "C:\Documents", "and" and "Settings\User\Temp\file.pdf" and complains about non existing file.

The workaround I am using for that is serve the files from a link. So in my app instead of sending the content type header and the pdf body I am sending html response with the link to generated document. The user then can click on the link and decide whether he wants to open it or save it. Fortunatelly the open option works in this approach, don't sure what the difference is (file is probably still saved in temp folder and passed to the acrobat executable as a parameter).
 
Sujatha Anandasabarinathan
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot for your reply. I will try it.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Where does this code live - in a JSP/JSP page? If so, it probably won't work, since you can't really stream binary content (like a PDF) from a JSP page. You need to use a servlet instead.

You should also at least print a message to the log files in your exception handlers. How else are you going to find out about problems?
 
Tim Holloway
Saloon Keeper
Posts: 27762
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ulf brings up a good point - there's no benefit to embedding the PDF code in a JSF process, and I'm surprised it worked at all.

JSF isn't the type of system where JSF has to be in control all the time. If a given web page makes more sense as a plain old JSP or servlet, just do a plain JSP/servlet. You don't need to shoehorn it into JSF.

If this is the error we think it is, it won't show up in the server log, though, since the problem is on the client.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic