【发布时间】:2020-09-15 11:29:46
【问题描述】:
我想在使用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','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.我如何设置这个标志?
【问题讨论】: