38156-vm/core/utils.py
Konrad du Plessis 370b0e9815 Add minimal section headers to all core/ files and CLAUDE.md coding style
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-20 00:07:26 +02:00

24 lines
558 B
Python

from io import BytesIO
from django.template.loader import get_template
from xhtml2pdf import pisa
from django.conf import settings
import os
# === PDF GENERATION ===
def render_to_pdf(template_src, context_dict={}):
template = get_template(template_src)
html = template.render(context_dict)
result = BytesIO()
# Enable logging for debugging
# pisa.showLogging()
# Create the PDF
pdf = pisa.pisaDocument(BytesIO(html.encode("UTF-8")), result)
if not pdf.err:
return result.getvalue()
return None