DomPDF错误未捕获的异常'Dompdf \ Exception'

时间:2018-07-02 10:52:55

标签: php css pdf dompdf

我的DOMPDF有问题。

我正在尝试使用DOMPDF生成表。

错误消息:

  

找不到行#1

完整的错误报告:

>     Fatal error: Uncaught exception 'Dompdf\Exception' with message 'The row #1 could not be found, please file an issue in the tracker
> with the HTML code' in /var/www/dompdf/src/Cellmap.php:415 Stack
> trace: #0 /var/www/dompdf/src/FrameReflower/TableRow.php(62):
> Dompdf\Cellmap->get_frame_height(Object(Dompdf\FrameDecorator\TableRow))
>     #1 /var/www/dompdf/src/FrameDecorator/AbstractFrameDecorator.php(894):
> Dompdf\FrameReflower\TableRow->reflow(NULL) #2
> /var/www/dompdf/src/FrameReflower/TableRowGroup.php(51):
> Dompdf\FrameDecorator\AbstractFrameDecorator->reflow() #3
> /var/www/dompdf/src/FrameDecorator/AbstractFrameDecorator.php(894):
> Dompdf\FrameReflower\TableRowGroup->reflow(NULL) #4
> /var/www/dompdf/src/FrameReflower/Table.php(489):
> Dompdf\FrameDecorator\AbstractFrameDecorator->reflow() #5
> /var/www/dompdf/src/FrameDecorator/AbstractFrameDecorator.php(894):
> Dompdf\FrameReflower\Table->reflow(Object(Dompdf\FrameDecorator\Block))
>     #6 /var/www/dompdf/src/FrameReflower/Block.php(845): Dompdf\FrameDecorator\AbstractFrameDecorator->reflo in
> /var/www/dompdf/src/Cellmap.php on line 415

这是我的 HMTL

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <link rel="stylesheet" type="text/css" href="styles.css">
    <title>Rechnung</title>
</head>
<footer>Footer on every page</footer>
<header>
    <img src="lib/gfx/xx.jpg" style="width: 30%; float:left;" alt="xx">
    <p style="width: 30%; float:right; margin-right: 5px;">
        xxxx xxxx GmbH
        <br>XXXX xx
        <br>XXX XXX
        <br>Deutschland
    </p>
</header>
<body>
    <main>
        <div class="ueberschrift">Rechnung</div>
        <table id="table">
            <thead class="thead-dark">
                <tr class="tr-head">
                    <div class="border-line-bottom">
                        <th scope="col" class="th-head">Stückzahl</th>
                        <th scope="col" class="th-head">Preis</th>
                        <th scope="col" class="th-head">Artikel</th>
                    </div>
                </tr>
            </thead>
            <tbody>
                <tr class="tr-body">
                    <td class="td-body">1</td>
                    <td class="td-body">12</td>
                    <td class="td-body">23</td>
                </tr>
            </tbody>
        </table>
    </main>
</body>
</html>

这是我的 CSS

@page
{
    margin: 100px 25px;
}

header {
    position: fixed;
    top: -60px;
    left: 0px;
    right: 0px;
    height: 100px;
    border-bottom: 1px solid black;
}

footer {
    position: fixed;
    bottom: -60px;
    left: 0px;
    right: 0px;
    height: 50px;
}

p {
    page-break-after: always;
}

p:last-child {
    page-break-after: never;
}

.ueberschrift {
    margin-top: 10%;
    display: block;
    margin-left: 45%;
    font-size: 20px;
    font-weight: bold;
}

#table {
    width: 100%;
}

.thead-dark {
    color: black;
    width: 100%;
}

.th-head {
    display: inline-block;
    margin-left: -20%;
}

#table .thead-dark th:nth-child(1) {
    display: inline-block;
    margin-left: 20px;
}

#table .thead-dark th:nth-child(2) {
    display: inline-block;
    margin-left: 90px;
}

#table .thead-dark th:nth-child(3) {
    display: inline-block;
    margin-left: 170px;
}

/*
    CSS für die Werte -> td
*/

#table .tr-body td:nth-child(1) {
    display: inline-block;
    margin-left: 20px;
}


#table .tr-body td:nth-child(2) {
    display: inline-block;
    margin-left: 90px;
}

#table .tr-body td:nth-child(3) {
    display: inline-block;
    width: 10%;
    background: red;
}

.border-line-bottom {
    width: 90%;
    margin: 0 auto;
    border-bottom: 1px solid black;
}

我认为问题可能是 显示:内联屏蔽 #table .tr-body td:nth-​​child(3) 当我移除显示标签时,它可以正常工作。

感谢帮助

1 个答案:

答案 0 :(得分:0)

尝试从CSS的th和td中删除display: inline-block;。 像@FatFreddy在回答中所说的那样,从<div class="border-line-bottom">中删除不必要的thead

当您用值inline-block覆盖th / td显示时,表中的css不是您想要的行为。