[Tutor] Problems serving up PDF

Luke Paireepinart rabidpoobear at gmail.com
Fri Sep 15 03:33:14 CEST 2006


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)
>
>   
You have a cgi script on your server that searches itself for a file and 
serves it to the user?
One note, you should be using \r\n instead of \n.
Also, you're putting \r\n\r\n after your header, right?
> 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
>
>   



More information about the Tutor mailing list