pythonqtpython-pdfkit

Error when trying to display the number of pages in PdfKit


A few days ago, I started working with PDFKIT, to generate reports in Python. My problem appears when I want to show the number of pages that the document has. I do not know what I am missing, or where I am failing. Below is the error that is shown, the code that I am using, and the resulting pdf.

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

Code:

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)  

Result:

image of the report


Solution

  • The problem was that the installed version of wkhtmltopdf was 0.12.4, which did not have the patched qt. The solution was to uninstall this version and install version 0.12.3 (which does have the patched 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/
    

    And this can be confirmed with:

    $ wkhtmltopdf --version
    wkhtmltopdf 0.12.3 (with patched qt)