which renderer should I use for pdf?

42 views
Skip to first unread message

Krishnakant

unread,
Jun 6, 2016, 2:03:39 AM6/6/16
to pylons-discuss
Dear all.
I am trying to send a pdf file to the browser.
In the view, reportlab is used to gerenate the pdf.
Then I would want an ajax call to get the pdf from that view callable.
So in the ajax call using jquery I can set application/pdf, but what
should I write in the renderer in view_config is my question.
And should I return the pdf as a value of a key in return?
happy hacking.
Krishnakant.

Christoph Zwerschke

unread,
Jun 6, 2016, 3:54:27 AM6/6/16
to pylons-...@googlegroups.com
Am 06.06.2016 um 08:02 schrieb Krishnakant:
> Then I would want an ajax call to get the pdf from that view callable.
> So in the ajax call using jquery I can set application/pdf, but what
> should I write in the renderer in view_config is my question.
> And should I return the pdf as a value of a key in return?

You don't need a renderer, just pass the PDF as the body of a Response:

def pdf_view(request):
output = BytesIO()
doc = BaseDocTemplate(output, pagesize=...)
story = []
...
story.append(Paragraph(...))
...
doc.build(story)
body = output.getvalue()
output.close()
return Response(body=body, content_type='application/pdf',
content_disposition='inline; filename="myfile.pdf"')

I usually create a view class and use a method instead. Then you can add
helper methods to the same class, like onPage() and onPageEnd().

-- Christoph


Reply all
Reply to author
Forward
0 new messages