[reportlab-users] Returning PDF to a browser?

Ben Mitchell reportlab-users@reportlab.com
Fri, 28 Nov 2003 14:23:40 -0800


Hi,

I'm trying to write a PDF that I've dynamically generated as a result 
of a form submission back to the requesting browser.

I'm having trouble getting it to display in the browser - it just 
presents itself as the raw PDF data...

My (simplified) code looks like this:


def go():
     print '''Content-Disposition: inline; filename=foo.pdf
Content-Type: application/pdf

     '''
     doc = SimpleDocTemplate(sys.stdout)
     doc.topMargin = inch*2.25
     Story = []
     style = styles["Normal"]
     parastr = "foo"
     p = Paragraph("<para leading=\"20\" fontName=\"helvetica\" 
fontSize=\"10\">%s</para>" % parastr, style)
     Story.append(p)

     doc.build(Story, pagetemplate, pagetemplate)


So if I call "go" as the first and only function after receiving the 
form input (which I'm now doing for test reasons) I think I'm returning 
the appropriate headers, followed by the document, which is printing to 
stdout.

But like I said, all I get is a browser full 'o raw PDF.

Can anyone point me in the right direction here?


Thanks,

-Ben