Steaming PDF from Python Script to IE

Stephen Thorne stephen at thorne.id.au
Sat Jun 21 21:26:20 EDT 2003


Nathan Treloar wrote:

> I'm trying to stream PDF content to a browser client via a python CGI
> script using:
> 
>     out = open("test.pdf", "rb").read()
>     print 'Content-type: application/pdf\n\n'
>     print out
> 
> However, IE is displaying the text and not launching Acrobat. If I
> remove one '\n' on the Content-type header Acrobat is launched but is
> not displaying the content. What am I missing? I've tried restarting
> IE, flushing the cache, etc..
> 
> (You probably want to know why I don't just send a link to the file.
> This is just a test, in my actual app the PDF content is coming from
> another service as a byte stream.)
> 
> Thanks in advance.

python automatically puts line-endings on when you do 
print 'foo'

What you probably want is actually

print 'Content-Type: application/pdf\r\n\r\n',
print out,

the ',' at the end of the line supresses lineendings. Also windows likes
\r\n for CRLF, whereas you were just sending LF (which is sufficient for
unixes).

Stephen Thorne.





More information about the Python-list mailing list