• 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

Cannot open PDF directly, save works

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

I'm having a strange problem

I have a webapp that can generate different file types(PDF, XLS, CSV)
Once file is generated, the response is sent where browser asked to open or save file. Save works for all files(including PDF), no problem.

Open however, works for every type except PDF. When clicking open, adobe reader starts, then it displays a popup error message saying: "There was an error opening this document. This file cannot be found".

I set content type to application/pdf. Although I've tried a bunch more:
application/download, application/force-download, application/octet-stream
application/x-unknown, multipart/download, etc.

I set Cache-control header to rivate, no-store, no-cache,
must-revalidate.
Pragma = no-cache

Content-disposition is set to : "attachment;filename="someFileName.pdf"

content-length is correctly set.

To work around an Excel problem I had to add extra url mapping where a request url which ended in the filename that matched the filename passed in content-disposition would generate the same file again. This is a known workaround for how retarded windows/Office/IE works, as Excel retrieves the file itself from the web server using the filename even if the browser has retrieved the file already. This only seems to happen with attached, not inline. Inline is not an option for me however.

This "filename URL" workaround is also available to whatever other programs opens PDF files, like Adobe reader. And looking at my logging I see adobe reader sending the request to get the document with the filename as the last part of the URI. The document is generated and sent back. So in effect it is generated twice. Which his fine, if it only worked!!

On linux everything works fine, PDFs opens fine in both ghost view or acroread. Quality programs!

I've run out of ideas, anyone see what I've forgotten?
Help!
 
Henrik Bentel
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In case someone else wonders, and just to reply to myself,

I found the solution at http://www.lowagie.com/iText/faq.html#msi.

Turns out my "Cache-Control" header was wrong.

In the servlet(actually, a struts action) that generate the files, I now set the headers to:
response.setHeader("Expires", "0");
response.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0");
response.setHeader("Pragma", "public");

And everything finally works.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Henrik, you just saved my day!
It took me forever searching the Net until I found your post. Great job.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Henrik,
Thank you very much.
Your reply help me a lot.

LH
[ November 18, 2004: Message edited by: Linh Hong ]
 
Enjoy the full beauty of the english language. Embedded in this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic