如何在python中使用pdfkit的print-media-type选项

问题描述

使用pdfkit打印时,我想在文档上打印水印。

使用ctrl+p从浏览器手动打印时,显示水印,但使用pdfkit打印时不显示水印。

我的假设是pdfkit可以完全按照在监视器上呈现的方式打印文档,并且可以通过在pdfkit的选项中设置print-media-type标志来使pdfkit完全按照浏览器的方式打印文档。

根据https://wkhtmltopdf.org/usage/wkhtmltopdf.txt文档,

--print-media-type              Use print media-type instead of screen
--no-print-media-type           Do not use print media-type instead of screen (default)
pdfkit的

选项,来自我的函数:

        _options = {
            'cookie': [
                ('csrftoken',options.get('csrftoken','none')),('sessionid',options.get('session_key',],'footer-center': 'Page [page] of [topage]','footer-right': DOC_VERSION.get(doctype,''),'footer-font-size': '9','print-media-type':,}

我尝试了以下组合,但没有一个起作用:

'print-media-type': 'True','print-media-type': True,'print-media-type': '',

问题:1.我的假设正确吗? 如果是,2.我该如何设置该标志?

解决方法

这对我有用:

options = {
  "disable-local-file-access": None,"enable-local-file-access": None,"print-media-type": None
}

pdfkit.from_file('index.html','out.pdf',options=options)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...