Using Reportlab Canvas- How to create an Option to print the pdf generated from the browser itself?

大城市里の小女人 提交于 2019-12-12 09:15:20

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!