Files
st01765 b695dd8054 Created new models to replicate out of and split coord app
Moved helpers and views to their respective new apps
2026-02-05 11:18:08 +11:00

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')