wkhtmltopdf / laravel-snappy不呈现页眉和页脚

问题描述

我当时正在使用xampp在Windows上的laravel项目中工作,但之后切换到ubuntu,我的pdf生成代码突然中断,没有任何更改。 我安装了laravel-snappy并将其指向wkhtmltopdf路径,但是突然没有显示页眉和页脚。 这是我的控制器代码

public function createPDF(){
        $userData = $this->getUserData(); //query and returns all users and their relations
        $pdf = App::make('snappy.pdf.wrapper');
        $footer = \view('supporting.footer')->render();
        $header = \view('supporting.header')->render();
        $userData = \collect([$this->userData[1]]); //just for faster rendering and testing
        $pdf->loadView('orders',['users' => $userData])
        ->setoption('margin-top','20mm')
        ->setoption('margin-bottom','20mm')
        ->setoption('minimum-font-size',25)
        ->setoption('header-html',$header)
        ->setoption('footer-html',$footer);
        $pdf->save($this->path);
}

我的标题视图:

<!DOCTYPE html>
<html lang="en">
<head>

</head>
<body>
    <div style="background: blanchedAlmond;color:green;">My Header is amazing<div>
</body>
</html>

这是我的页脚视图:

<!DOCTYPE html>
<html lang="en">
<head>
</head>
<body>
    <div style="background: blanchedalmond; color:green;">copyright &copy; 2020</div>
</body>
</html>

我的订单视图:(仅一些基本表格)

<!DOCTYPE html>
<html lang="en">

<head>
    <Meta charset="UTF-8">
    <Meta name="viewport" content="width=device-width,initial-scale=1.0">
    <title>Order Layout</title>
    <style>
        *{
            font-family: cursive;
        }

        .wrapper {
            display: block;
        }

        .invoice {
            display: block;

            width: 80%;
            margin: 0 auto;
            margin-top: 10px;
            padding-top: 10px;
            padding-bottom: 10px;
            background: #d3d3d3;
            page-break-inside: avoid !important;
            padding-left: 20px;
        }

        .order-items {
            padding-left: 100px;
        }

        .table {
            width: 90%;
            align-self: center;
            border: 1px solid black;
            page-break-inside: avoid !important;
            orphans: 15;
        }
        .table>* {
            text-align: center;
        }
    </style>
</head>

<body>

    <main class="wrapper">
        @foreach ($users as $user)

        @PHP
        $orders = $user->orders //just for renaming
        @endPHP
        @foreach ($orders as $order)
        
        <div class="invoice">
            @PHP
            $sum=0;
            @endPHP
            <h2>{{$user->name}}: {{$order->id}}</h2>
            <div class="order-items">
                <table class="table" border="1">
                    <thead>
                        <tr>
                            <th>Product Name</th>
                            <th>Unit Price</th>
                            <th>Qty</th>
                            <th>subtotal</th>
                        </tr>
                    </thead>
                    <tbody>
                        @foreach ($order->products as $product)
                        <tr>
                            <th>
                                {{$product->name}}<br>
                            </th>
                            <td>{{$product->unit_price}}</td>
                            <td>{{$product->pivot->quantity}}</td>
                            @PHP
                            $sum+= $product->pivot->quantity*$product->unit_price
                            @endPHP
                            <td>{{$product->pivot->quantity*$product->unit_price}}</td>
                        </tr>
                        @endforeach
                    </tbody>
                    <tfoot>
                        <tr>
                            <th colspan="3">Total:</th>
                            <td>{{$sum}}</td>
                        </tr>
                    </tfoot>
                </table>
            </div>
        </div>
        @endforeach
        @endforeach
    </main>
</body>

</html>

这是我的apache配置文件

<VirtualHost *:80>
    ServerAdmin user@email.com
    DocumentRoot /home/frapto/frapto/pdf-mock/public
    ErrorLog "/home/frapto/example.error.log"
    CustomLog "/home/frapto/example.access.log" combined
    <Directory "/home/frapto/frapto/pdf-mock/public">
        Options -Indexes
        DirectoryIndex index.PHP index.html
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>

这是pdf布局的比较: https://imgur.com/a/ySpSjJN

不会生成页眉和页脚,并且跨页断开表时不会重复表头

我没有更改代码中的任何内容,我不知道为什么它突然崩溃了,我该如何解决?我尝试了多个CSS属性,路线以及所有我能找到的东西,但运气不佳。

我愿意切换库。尽管我的pdf可能很大(目前大约有3000页,但可能会增长或缩小),但dompdf根本无法工作,tcpdf的文档不清晰,而mpdf太慢。我要生成的是每页上都有页眉和页脚的div /表(及其CSS)。

谢谢

编辑::原来我只需要安装wkhtmltopdf库的qt修补版本,而不是普通版本

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)