0

我正在使用 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/tables(和它们的 css)。

谢谢

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

4

0 回答 0