[reportlab-users] Returning PDF to a browser?

David Fraser reportlab-users@reportlab.com
Sat, 29 Nov 2003 09:51:25 +0200


Carl Waldbieser wrote:

>You are a little vague on some points, though I think Iget the general gist
>of what you are trying to accomplish.  I wrote up a little demo at work that
>uses Reportlab to dynamically create a PDF file and send it back to an
>Internet Explorer browser as the HTTP response.  Like you, I was getting the
>raw PDF showing up in the browser instead of Acrobat reader popping up in
>the browser.  The trick to making it work was to observe the headers that
>were sent when I typed in the URL of a static PDF file and observe what
>headers were returned to the browser.  I believe that the "Accept-Ranges:
>bytes" might do the trick for you, though I won't be back to work to double
>check until Tuesday due to the holidays here.
>
>Carl Waldbieser
>  
>
You should also check for Internet Explorer that the URL actually ends 
with a .pdf  as it sometimes seems to get the type from the extension 
rather than the Content type in my experience

David

>----- Original Message ----- 
>From: "Ben Mitchell" <ben@mitchellfamily.com>
>To: <reportlab-users@reportlab.com>
>Sent: Friday, November 28, 2003 5:23 PM
>Subject: [reportlab-users] Returning PDF to a browser?
>
>
>  
>
>>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
>>
>>_______________________________________________
>>reportlab-users mailing list
>>reportlab-users@reportlab.com
>>http://two.pairlist.net/mailman/listinfo/reportlab-users
>>    
>>
>
>_______________________________________________
>reportlab-users mailing list
>reportlab-users@reportlab.com
>http://two.pairlist.net/mailman/listinfo/reportlab-users
>
>  
>