1👍
Try:
# code...
page = renderPDF.drawToFile(drawing, 'example.pdf', 'lineplot with dates')
response = HttpResponse(page, mimetype='application/pdf')
I’m using reportlab.pdfgen.canvas
and it works great.
Keep in mind that it’s client’s browser (and/or OS) job to open your file in browser after recognizing it as a PDF.
EDIT:
That’s how I present invoices on some Web2Print solution:
from django.http import HttpResponse
from reportlab.pdfgen import canvas
def invoice_to_response(request, invoice):
response = HttpResponse(mimetype='application/pdf')
p = canvas.Canvas(response, pagesize='A4', pageCompression=0)
# here I draw on 'p' like p.setFillColor(black)
p.showPage()
p.save()
return response
Source:stackexchange.com