Error while converting HTML to PDF with HTML2PDF

Asked

Viewed 228 times

1

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

Tabela

My HTML 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%;
        }

        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? Thank you!

  • Try placing the edge by the type CSS table { border: 1px solid black}

  • It was the same. What I can’t understand is that if I take the attribute border works perfectly, but the table is without the edge, and I need it :/

  • Try putting a <table style="box-shadow: 0 0 0 1px black"> sometimes it works... takes a test

  • All right, I’ll see you test it here!

  • It worked, brother! Thank you!

  • 1

    Mass ;D I can post as response?

  • 1

    Of course, you can!

Show 2 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.