Laravel dompdf 未显示为视图

Laravel dompdf not displayng as the view

我正在尝试生成书籍封面,在我的 blade 视图中它看起来不错,但是当我生成 pdf 时它看起来不像预览

书前预览

PDF 已生成

我的 blade 视图:

<!DOCTYPE html>
<html>
<head>
    <link rel="stylesheet" href="css/style.css">
    <title>Cover</title>
</head>
<body class="bg-cover-blue">
    <div>
        <h1 style="margin-left: 880px;margin-top: 290px;"> {{ $title }}</h1>
        <p style="margin-left: 980px;"> {{ $owner }}</p>
    </div>
</body>
</html>

我的css:

.bg-cover-blue{
    background-image: url(../img/covers/blue.jpg);
    background-position: center;
    background-size: cover;
    background-repeat: no-repeat;
}
$data = ['title' => $title, 'owner' => $owner, 'color' => $covercolor,]; $pdf = PDF::loadView('pdf.covertest', $data) ->save(storage_path('../public/pdf/cover/') . 'cover'.$id.'.pdf');

Hi Ramiro, This might not really solve your problem, but it sure will help you understand what's going on.

According to https://github.com/barryvdh/laravel-dompdf, I guess you probably should change your pdf orientation to horizontal in other to capture more screen area.

I am finding it difficult to understand why the library refuse to capture the whole screen regardless of the orientation, it's like it target a specific viewport or so, or maybe because it's an image ? well, this is not detailed in the documentation.

Below is what I am able to achieve, it very much closer to what you want and you might like it for time sake.

Blade Sample code:

<!DOCTYPE html>
<html style="margin: 0; padding: 0">
<head>
    <title>Cover</title>
</head>
<body class="bg-cover-blue" style="margin: -15%; background-size: cover; background: url('https://i.stack.imgur.com/UWJtU.jpg') no-repeat center;">
<div>
    <h1 style="margin-left: 880px; margin-top: 350px;"> {{ $title }}</h1>
    <p style="margin-left: 980px;"> {{ $owner }}</p>
</div>
</body>
</html>

Php Sample Code:

function returnView(){

        $data = [
            'owner'=>"Ramiro",
            'title'=>"Whosebug"
        ];

        $path = "/qrcodes/"."Whosebug.pdf";

       $pdf = PDF::loadView('email.sample', $data)->setPaper('letter', 'landscape')->save(public_path($path));

        return $pdf->stream("Halloa.pdf");

       //return view('email.sample', $data);
    }

注意:负边距实际上并不重要,没有它看起来还是不错的。