Steaming PDF from Python Script to IE

Stephen Thorne stephen at
Sun Jun 22 03:26:20 CEST 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

Stephen Thorne.

More information about the Python-list mailing list