Skip to content

Instantly share code, notes, and snippets.

@byroot
Created March 8, 2011 22:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save byroot/861196 to your computer and use it in GitHub Desktop.
Save byroot/861196 to your computer and use it in GitHub Desktop.
import ho.pisa as pisa
from django.template import loader
from django.http import HttpResponse
def render_to_pdf(*args, **kwargs):
response = HttpResponse('', mimetype='application/pdf')
response['Content-Disposition'] = 'attachment; filename=%s' % kwargs.pop('filename', 'something.pdf')
document = loader.render_to_string(*args, **kwargs)
print document
pisa.CreatePDF(document, response)
return response
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment