Patrick Lewis wrote: > The key is the content_type in the @expose decorator, which sets > cherrypy.response.headers["Content-Type"], and ultimately lets your > browser know what is coming down the tube. (For PDF's this type is > "application/pdf", http://www.iana.org/assignments/media-types/ for > others). So, you are going to need to come up with a strategy in your > app to identify what type of a document/file you are dealing with, and > then set cherrypy.response.headers["Content-Type"] appropriately. > > If you have a controller specific to displaying just PDFs, you should > be able to set the decorator as: > @turbogears.expose(content_type="application/pdf") > There's actually been some discussion on the mod_python list on this topic recently. It turns out that IE particularly can be difficult to deal with, and you need to know the correct recipe rather than just doing what standards would suggest. Rather than force you to search, here's the relevant quote - you should be able to find the thread with Google if you need it.
regards Steve > Hey, that did it! > > I changed the Cache-Control header to '' and now it works. I will run it > through more tests tomorrow, but for now it appears to be working. Also, if > I set the Content-Disposition to attachment, I get the filename that I > specify in the filename parameter. The filename doesn't seem to come > through if I specify inline. > > Colin, I can't thank you enough for the help. This will make it really easy > to build dynamic pdf's and get them out to our users, and now I don't have > to have them all pre-generated and stored on our servers. > > -Jim > > -----Original Message----- > From: Colin Bean [mailto:[EMAIL PROTECTED] > Sent: Monday, October 16, 2006 6:52 PM > To: Jim Steil > Subject: Re: [mod_python] ReportLab integration > > Hi Jim, > > Well, I uncovered some weird behavior within IE, and I think I found > part of the problem. I wrote a standalone module (without publisher) > that read a pdf off disk and sent the string value to the request, to > try to simulate your module's behavior. This is on Apache 2.2.0, > mod_python 3.2.10 on Fedora Core 5, tested with IE 6 and firefox. > > It basically goes back to that comment in Graham's code about how > setting the cache-control header caused IE to not display the PDF. > While you never set these by hand, you do use a session cookie, which > sets the Cache-Control header to 'no-cache="set-cookie"', and > apparently this is enough to break IE. In my test handler, the pdf > displayed fine in the browser when I didn't use a session, but would > only give me a "save to disk" dialog when I did. > > So you might try removing any session code from your example to see if > it would work (I'm guessing you'll need some kind of authentication in > the future so this is probably not going to be a long-term solution, > but it should at least confirm that this is the problem). Forgive my > ignorance of publisher; I forget if it automatically creates a > session. If it does, the only way to get this to work would be as a > standalone handler. > > Another option I found, which worked but seems sketchy was to set the > Cache-Control header to an empty string right before sending the > headers. When I did this, the PDF displayed fine, and the pysid > headers where still there, but I'd image that the cache-control header > was there for a reason and I'm sure this could break in unexpected > ways. > > Finally, the content-dispositon thing doesn't really matter -- it does > give you a nice filename when you choose "save as", but it didn't > affect whether or not IE would display the pdf right. So sorry to put > you through all that other stuff ;) > > Hopefully some of that made sense, let me know if you get this working. > > -Colin [...] -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC/Ltd http://www.holdenweb.com Skype: holdenweb http://holdenweb.blogspot.com Recent Ramblings http://del.icio.us/steve.holden --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "TurboGears" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/turbogears -~----------~----~----~----~------~----~------~--~---

