python - 如何在 python 中使用 pdfkit 的 print-media-type 选项
问题描述
使用 pdfkit 打印时,我想在文档上打印水印。
使用浏览器手动打印时ctrl+p
,会显示水印,但使用 pdfkit 打印时不显示。
我的假设是 pdfkit 完全按照它在显示器上呈现的方式打印文档,并通过print-media-type
在 pdfkit 的选项中设置标志来使 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','none')),
],
'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)
推荐阅读
- loops - Loop preventing event from firing
- swift - 插入或更新对象时,NSFetchedResultsController 未检测到更改类型
- c# - Xamarin.Android 中的 X509Store 为空
- javascript - 反应返回带有变量值的 HTML
- mysql - 无法在 MySQL 中创建两个表
- javascript - 如何从嵌套的延迟 then() 函数返回
- javascript - this.state 在反应组件中引用了什么?
- samsung-smart-tv - 无法通过命令行调试三星电视网络应用程序
- c++ - 更改注册表中的条目键后,鼠标滚轮在 W10(V.1803 - build 17134.165)中的 C++ Builder 6.0(Borland)上不起作用
- c# - 将工厂注入类