[Tutor] Problems serving up PDF
Tim Johnson
tim at johnsons-web.com
Fri Sep 15 03:53:00 CEST 2006
* Luke Paireepinart <rabidpoobear at gmail.com> [060914 17:36]:
> Tim Johnson wrote:
> >Hi:
> >
> >This is *not* really a python problem, but :-) since this
> >is such an helpful list and others may have the same issue...
> >
> >I have a python script which searches a server for a pdf file
> >and if found, reads the file to stdout, as one would read html
> >to stdout.
> >
> >The question is really about the proper content-type:
> >
> >Both of the following functions have been tried:
> >
> >def pdf_header1(file_name,length):
> > """ Serve a PDF document via CGI with content length."""
> > print (
> > 'Content-type: application/pdf\n'
> > 'Content-Length: %d\n'
> > 'Content-Disposition: attachment;filename="%s"\n'
> > ) % (length,file_name)
> >
> >def pdf_header(file_name,length):
> > """ Serve a PDF document via CGI with content length."""
> > print (
> > 'Content-type: application/pdf\n'
> > 'Content-Disposition: inline; filename=%s\n'
> > 'Content-length: %d\n'
> > ) % (file_name,length)
> >
> >
Hi Luke:
> You have a cgi script on your server that searches itself for a file and
> serves it to the user?
Correct.
> One note, you should be using \r\n instead of \n.
Both development and deployment are on a linux OS, so
this is the correct procedure. However, I don't think that
using '\r' does any harm on *nix....
in fact, it would be the more portable approach.
Thanks for pointing that out.
> Also, you're putting \r\n\r\n after your header, right?
Not sure what you mean. Either of the functions provide the
header. Could you explain further?
regards
tim
> >Regardless of which is used, on Mozilla, I have the following
> >response:
> > A dialog that names the file, identifies the filetype, and
> > gives a choice of whether to download or open the file.
> > when the choice is made, progress is reported via another
> > window and the selected action occurs when download is finished.
> >
> Sounds like it's working to me.
> >On Internet Explorer 6, Windows XP, the user experience is different.
> >IE ignores the file name, and does no progress reporting, but does
> >"understand" the file type.
> >
> Sounds like it's working to me.
>
>
> As far as I can tell, it seems to me like you have some file (example .wmv)
> that I.E. is saying 'okay I know how to open this' and it tries to do
> something with it.
> Firefox, humble as it is, admits that it doesn't know what to do and
> just lets you download it.
> If this is the case, then it's a configuration issue with IE that's
> making it attempt to open the file.
> You could just as well configure Firefox to automatically open these
> files too, although
> that doesn't mean that it'll work :)
>
> So unless you can be more specific, I'd say that it's just a difference
> in the browser and not a problem
> with your code at all. Do I not understand correctly?
> HTH,
> -Luke
> >Does anyone have any experience with this issue? Or could anyone
> >recommend a more appropriate place to post this question?
> >Thanks
> >tim
> >
> >
--
Tim Johnson <tim at johnsons-web.com>
http://www.alaska-internet-solutions.com
More information about the Tutor
mailing list