views:

115

answers:

2

I'm using pylons to serve a dynamically generated pdf document for reporting: my approach works in firefox & chrome (it displays the pdf inline if the plugin is available or otherwise downloads it) but IE (7 & 8) only show a blank page and doesn't prompt for download. IE correctly shows PDFs generated by other websites, though.

Don't know if it matters but the page is accessed through HTTPS.

My controller does the following:

  • renders the source page through mako
  • converts the html to pdf using pisa
  • adds these headers to the response: Content-type: application/pdf and Content-disposition: inline; filename=file.pdf

Do you have any suggestion? I seem to be stuck and cannot think of anything else to try.

+2  A: 

In django I do this:

response['Content-Disposition'] = 'attachment; filename=rawr.pdf'

So try changing inline to attachment and see what happens.

Oli
+2  A: 

Not sure if this helps, but in IE6 I was getting all sorts of strange browser errors when I tried to stream dynamically generated PDFs. The errors were different depending on whether the content disposition header said inline or attachment, but it was a train-wreck either way.

The issued turned out to be that IE6 must cache the PDF in order to pass it to Acrobat Reader, and the default headers in a Pylons response say "don't cache this". I allowed caching for 10 seconds by adding:

    del response.headers['Cache-Control']
    del response.headers['Pragma']
    response.cache_expires(seconds=10)

to the controller that returns the PDF, and all was well.

Doug Latornell