尝试在PdfKit中显示页数时出错

问题描述 投票:1回答:1

几天前,我开始使用PDFKIT,用Python生成报告。当我想显示文档所具有的页数时,会出现我的问题。我不知道我错过了什么,或者我失败了。下面是显示的错误,我正在使用的代码以及生成的pdf。

Error: The switch --footer-right, is not support using unpatched qt, and will be ignored

码:

import pdfkit

options = {
    'page-size': 'Letter',
    'margin-top': '1cm',
    'margin-right': '1cm',
    'margin-bottom': '1cm',
    'margin-left': '1cm',
    '--footer-right': '[page]',
}
body = u"""
    <html>
        <head>
            <meta name="pdfkit-page-size" content="Letter"/>
            <meta name="pdfkit-orientation" content="Portrait"/>
            <meta charset="utf-8">
            <style>
                .td_left{
                    text-align: left;
                }
                .td_rigth{
                    text-align: right;
                }
                img{
                    width: 150px;
                    height: auto;
                    position: absolute;
                    top: 0;
                    left: 0;
                }
            </style>
        </head>
        <body>
            <img src='/home/produccion/Downloads/logo.png'>
            <center>
                <h2><b>NOMBRE DE LA EMPRESA - NOMBRE DE LA SUCURSAL</b></h2>
                <h3><b>NIT: 000.000.000-0</b></h3>
                <h2><b>CONTABILIZACIÓN</b></h2>
            <center>
            <table>
                <thead>
                    <th>CUENTA PUC</th>
                    <th>BOD</th>
                    <th class='td_left'>TERCERO</th>
                    <th class='td_rigth'>DOC N°</th>
                    <th class='td_rigth'>VENCE</th>
                    <th class='td_rigth'>CANTIDAD</th>
                    <th class='td_rigth'>DÉBITO</th>
                    <th class='td_rigth'>CRÉDITO</th>
                </thead>
                <tbody>
    """
for i in range(15):
    body += """<tr>
                    <td>0000-00-000</td>
                    <td>{0}</td>
                    <td class='td_left'>NOMBRE DEL TERCERO</td>
                    <td class='td_rigth'>AAA0000000001</td>
                    <td class='td_rigth'>01/01/2000</td>
                    <td class='td_rigth'>0.0</td>
                    <td class='td_rigth'>00000000</td>
                    <td class='td_rigth'>00000000</td>
                </tr>""".format(i+1)
body += """</tbody>
            </table>
        </body>
    </html>"""
pdfkit.from_string(body, 'ejemplo.pdf', options=options)  

结果:

python qt python-pdfkit
1个回答
0
投票

问题是wkhtmltopdf的安装版本是0.12.4,没有修补的qt。解决方案是卸载此版本并安装版本0.12.3(确实有修补的qt):

cd ~
wget https://github.com/wkhtmltopdf/wkhtmltopdf/releases/download/0.12.3/wkhtmltox-0.12.3_linux-generic-amd64.tar.xz
tar vxf wkhtmltox-0.12.3_linux-generic-amd64.tar.xz 
cp wkhtmltox/bin/wk* /usr/local/bin/

这可以通过以下方式确认:

$ wkhtmltopdf --version
wkhtmltopdf 0.12.3 (with patched qt)
© www.soinside.com 2019 - 2024. All rights reserved.