Skip to content

Instantly share code, notes, and snippets.

@rturowicz
Last active December 15, 2015 07:59
Show Gist options
  • Save rturowicz/5227967 to your computer and use it in GitHub Desktop.
Save rturowicz/5227967 to your computer and use it in GitHub Desktop.
django trml2pdf - create pdf from template
from django.utils.encoding import smart_str
import trml2pdf
filename = "advert-%s.pdf" % id
response = HttpResponse(mimetype='application/pdf')
response['Content-Disposition'] = 'attachment; filename=%s' % filename
t = loader.get_template('print/pdf/advert.rml')
c = Context({
'filename' : filename,
'advert' : advert,
'request' : request,
})
pdf = trml2pdf.parseString(smart_str(t.render(c)))
response.write(pdf)
return response
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment