Skip to content

Commit

Permalink
Merge pull request #1 from ojii/master
Browse files Browse the repository at this point in the history
Added a render_to_pdf method in django_xhtml2pdf.utils
  • Loading branch information
chrisglass committed Aug 25, 2011
2 parents 07eb93f + eb60952 commit ec79ad7
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions django_xhtml2pdf/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit ec79ad7

Please sign in to comment.