if pdf:
# I need to build the Response object myself
from pyramid.renderers import render
from pyramid.response import Response
result = render('frontend:templates/student_pyp_report.pt',
dict(
title=title,
report=report,
student=student,
pdf=True
),
request=request)
response = Response(
result,
content_disposition="attachment; filename={}.pdf".format("test"),
content_type = "application/pdf",
charset="utf-8"
)
return response
else: return dict( title=title, report= report, student=student, pdf=False )
On 25 Jan 2015, at 14:40, Adam Morris <adam....@igbis.edu.my> wrote:Okay, I get that bit now, and coded it up, but when I go to render it, I use the pyramid.renderers.render object but obviously it ends up downloading a corrupted file because it's not even in PDF format.
So does reportlab have something to take that html/css and paint it to a Canvas or something?
from pyramid.renderers import render
from pyramid.response import Response
import pdfkit
import StringIO
result = render('frontend:templates/student_pyp_report.pt',
dict(
title=title,
report=report,
student=student,
pdf=True
),
request=request)
pdffileio = StringIO.StringIO()
pdffileio.write(result)
pdf_as_string = pdfkit.from_file(pdffileio, False) # False means return it as a string
response = Response(
pdf_as_string,
content_disposition="attachment; filename={}.pdf".format("test"),
content_type = "application/pdf",
charset="utf-8"
)
#pdffileio.close()
return response
--
You received this message because you are subscribed to the Google Groups "pylons-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pylons-discus...@googlegroups.com.
To post to this group, send email to pylons-...@googlegroups.com.
Visit this group at http://groups.google.com/group/pylons-discuss.
For more options, visit https://groups.google.com/d/optout.