From eb609522d919bb66a8ddd3af9d7eedd745ab7a58 Mon Sep 17 00:00:00 2001 From: Jonas Obrist Date: Thu, 25 Aug 2011 22:24:07 +0300 Subject: [PATCH] Added a render_to_pdf method in django_xhtml2pdf.utils --- django_xhtml2pdf/utils.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/django_xhtml2pdf/utils.py b/django_xhtml2pdf/utils.py index bcdf070..2da641c 100644 --- a/django_xhtml2pdf/utils.py +++ b/django_xhtml2pdf/utils.py @@ -61,3 +61,10 @@ def generate_pdf(template_name, file_object=None, context=None): # pragma: no co tmpl = get_template(template_name) generate_pdf_template_object(tmpl, file_object, context) return file_object + +def render_to_pdf_response(template_name, context=None, pdfname=None): + file_object = HttpResponse(content_type='application/pdf') + if not pdfnmae: + pdfname = '%s.pdf' % os.path.splitext(os.path.basename(template_name))[0] + file_object['Content-Disposition'] = 'attachment; filename=%s' % pdfname + return generate_pdf(template_name, file_object, context)