Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- html_string = render_to_string('shop/pdf_invoice.html', context)
- with codecs.open('out.html', 'w', 'utf-8') as f:
- f.write(html_string)
- html = HTML(string=html_string)
- result = html.write_pdf()
- response = HttpResponse(content_type='application/pdf;')
- response['Content-Disposition'] = 'inline; filename=invoice' + \
- str(customers.id)+customers.customer_uid + customers.customer_name + '.pdf'
- response['Content-Transfer-Encoding'] = 'utf-8'
- with tempfile.NamedTemporaryFile(mode='wb+') as output:
- output.write(result)
- output.flush()
- output = open(output.name, 'wb+')
- response.write(output.read())
- return response
Advertisement
Add Comment
Please, Sign In to add comment