本文介绍了使用Reportlab Canvas-如何创建一个选项来打印从浏览器本身生成的pdf?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是使用Reportlab为我生成pdf的代码。

Here is the code which generates pdf for me using Reportlab.

现在,它只是在浏览器中显示pdf,并在共振中包含'附件'之后.header ['Content-Disposition'],它下载pdf。

Now, it just shows the pdf in the browser, and after including 'attachment' in the resonse.header ['Content-Disposition'], it downloads the pdf.

但我想要的是你在浏览器中的rint选项,它甚至允许你选择你的打印机。有可能吗?

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()


推荐答案

根据你可以添加这两行来获得所需的结果:

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}\);)>>'

希望有所帮助:)

这篇关于使用Reportlab Canvas-如何创建一个选项来打印从浏览器本身生成的pdf?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-03 08:36