Error converting HTML to PDF with HTML2PDF

1

Next, I'm trying to convert an HTML file that has a table to PDF using the HTML2PDF library but when I put a table with the border="1" attribute the table looks like this:

MyHTML:

<!doctypehtml><htmllang="en-us">
<head>
    <title>Relatório de Tarefas</title>
    <style type="text/css">
        * {
            background: transparent !important;
            color: #000 !important;
            text-shadow: none !important;
            filter: none !important;
            -ms-filter: none !important;
        }

        body {
            margin: 0;
            padding: 0;
            line-height: 1.3em;
        }

        @page {
            margin: 0.5cm;
        }

        body {
            font: 10pt Arial, "Times New Roman", Times, serif;
            color: #000;
        }

        h1 {
            font-size: 24pt;
        }

        h2 {
            font-size: 18pt;
        }

        h3 {
            font-size: 14pt;
        }

        p {
            widows: 3;
            margin: 5px 0;
        }

        table {
            border-collapse: collapse;
            width: 100%;
        }

        table td, th {
            padding: 10px;
            text-align: left;
        }

        .to-center {
            text-align: center;
        }
    </style>
</head>
<body>
    <h1>Relatório de Tarefas</h1>
    <p style="margin-top: -20px">Emitido em: {{ issueDate }}</p> <br/>
    <table border="1">
        <thead>
            <tr>
                <th class="to-center">#</th>
                <th>Assunto</th>
                <th>Descrição</th>
                <th class="to-center">Progresso</th>
                <th>Condomínio</th>
                <th class="to-center">Status</th>
                <th class="to-center">Criado em</th>
            </tr>
        </thead>
        <tbody>
            {% for task in tasks %}
                <tr>
                    <td class="to-center">{{ task.id }}</td>
                    <td>{{ task.subject }}</td>
                    <td>{{ task.description }}</td>
                    <td class="to-center">{{ task.percentage_progress }}%</td>
                    <td>{{ task.condominium_name }}</td>
                    <td class="to-center">{{ task.status_label }}</td>
                    <td class="to-center">{{ dateTimeConvert(task.created_at) }}</td>
                </tr>
            {% endfor %}
        </tbody>
    </table>
</body>

Has anyone ever had this problem or know how to solve it? Thanks!

    
asked by anonymous 17.12.2018 / 17:59

1 answer

0

I do not know the HTML2PDF API, but one of the options to get around the border problem is to box-shadow 1px, so what you will use in the code is box-shadow , but in rendering in page will visually look like a fence.

table {
   border-collapse: collapse;
   width: 100%;
   box-shadow: 0 0 0 1px black;
 }

Here's how it goes in your code:

<!doctype html>
<html lang="en-us">
<head>
    <title>Relatório de Tarefas</title>
    <style type="text/css">
        * {
            background: transparent !important;
            color: #000 !important;
            text-shadow: none !important;
            filter: none !important;
            -ms-filter: none !important;
        }

        body {
            margin: 0;
            padding: 0;
            line-height: 1.3em;
        }

        @page {
            margin: 0.5cm;
        }

        body {
            font: 10pt Arial, "Times New Roman", Times, serif;
            color: #000;
        }

        h1 {
            font-size: 24pt;
        }

        h2 {
            font-size: 18pt;
        }

        h3 {
            font-size: 14pt;
        }

        p {
            widows: 3;
            margin: 5px 0;
        }

        table {
            border-collapse: collapse;
            width: 100%;
            box-shadow: 0 0 0 1px black;
        }

        table td, th {
            padding: 10px;
            text-align: left;
        }

        .to-center {
            text-align: center;
        }
    </style>
</head>
<body>
    <h1>Relatório de Tarefas</h1>
    <p style="margin-top: -20px">Emitido em: {{ issueDate }}</p> <br/>
    <table>
        <thead>
            <tr>
                <th class="to-center">#</th>
                <th>Assunto</th>
                <th>Descrição</th>
                <th class="to-center">Progresso</th>
                <th>Condomínio</th>
                <th class="to-center">Status</th>
                <th class="to-center">Criado em</th>
            </tr>
        </thead>
        <tbody>
            {% for task in tasks %}
                <tr>
                    <td class="to-center">{{ task.id }}</td>
                    <td>{{ task.subject }}</td>
                    <td>{{ task.description }}</td>
                    <td class="to-center">{{ task.percentage_progress }}%</td>
                    <td>{{ task.condominium_name }}</td>
                    <td class="to-center">{{ task.status_label }}</td>
                    <td class="to-center">{{ dateTimeConvert(task.created_at) }}</td>
                </tr>
            {% endfor %}
        </tbody>
    </table>
</body>
    
17.12.2018 / 19:39