问题
Here is the code which generates pdf for me using Reportlab.
Now, it just shows the pdf in the browser, and after including 'attachment' in the resonse.header ['Content-Disposition'], it downloads the pdf.
But what i want is the rint option which comes you in the browser, which even allows you to choose your printer. is it possible ?
data = "raghav"
p = canvas.Canvas(self.response.out)
p.drawString(50, 700, data)
p.showPage()
self.response.headers['Content-Type'] = 'application/pdf'
self.response.headers['Content-Disposition'] = 'attachment;filename=testpdf.pdf'
p.save()
回答1:
according to http://blog.adlibre.org/2012/04/05/automatically-print-pdf-generated-reportlab/ you can add these two lines to get the desired result:
from reportlab.pdfbase import pdfdoc
pdfdoc.PDFCatalog.OpenAction = '<</S/JavaScript/JS(this.print\({bUI:true,bSilent:false,bShrinkToFit:true}\);)>>'
hope it helps :)
来源:https://stackoverflow.com/questions/13984761/using-reportlab-canvas-how-to-create-an-option-to-print-the-pdf-generated-from