b695dd8054
Moved helpers and views to their respective new apps
14 lines
497 B
Python
14 lines
497 B
Python
from io import BytesIO
|
|
|
|
from django.http import HttpResponse
|
|
from django.template.loader import get_template
|
|
from xhtml2pdf import pisa
|
|
|
|
|
|
def render_to_pdf(template, context):
|
|
html = get_template(template).render(context)
|
|
result = BytesIO()
|
|
pdf = pisa.pisaDocument(BytesIO(html.encode("ISO-8859-1")), result)
|
|
if pdf.err:
|
|
return HttpResponse("Invalid PDF", status_code=400, content_type='text/plan')
|
|
return HttpResponse(result.getvalue(), content_type='application/pdf') |