【问题标题】:how to use pdfkit's print-media-type option in python如何在 python 中使用 pdfkit 的 print-media-type 选项
【发布时间】: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.我如何设置这个标志?

【问题讨论】:

    标签: python pdfkit


    【解决方案1】:

    这对我有用:

    options = {
      "disable-local-file-access": None,
      "enable-local-file-access": None,
      "print-media-type": None
    }
    
    pdfkit.from_file('index.html', 'out.pdf', options=options)
    

    【讨论】:

      猜你喜欢
      • 2013-05-07
      • 1970-01-01
      • 1970-01-01
      • 2017-10-01
      • 1970-01-01
      • 2018-12-14
      • 2019-08-17
      • 1970-01-01
      • 2020-03-31
      相关资源
      最近更新 更多