response = HttpResponse(mimetype='application/pdf')
response['Content-Disposition'] = 'attachment; filename=' + filename
pdf = pisa.CreatePDF(contents, response)
How to generate a PDF from an HTML / CSS (including images) source in Python?