0

当您只有简单的 HTML 代码且无需导入任何内容时,可以从刀片视图轻松生成简单的 PDF。

但是,如果我将href属性添加到外部位置,则 snappyPDF 根本不起作用。

我正在使用 Laravel 8 Jestream。

这是我的刀片文件的一部分:

<!doctype html>
<html lang="es">
<head>
    <link rel="preconnect" href="https://fonts.gstatic.com">
    <link href="https://fonts.googleapis.com/css2?family=Sorts+Mill+Goudy&display=swap" rel="stylesheet">
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Certificate</title>
    <style media="screen">
        body {
            font-family: 'Sorts Mill Goudy', serif;
            text-align:center;
            background-image: url("https://images.pexels.com/photos/242236/pexels-photo-242236.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=750&w=1260");
            background-repeat: no-repeat;
            background-position: left top;
            width:816px;
            height:1056px;
            border: 10px solid #e6e6e6
        }
    </style>
<body>
<div class="some">
    <div class="other">
        <img class="logo" src="https://images.pexels.com/photos/1337386/pexels-photo-1337386.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=750&w=1260" alt="Logo">
    </div>
</div>
</body>
</html>

据我所知,问题出现在我添加src="https external"url(https//external) 尝试通过 Snappy 生成 PDF 时,无法生成 pdf。

我该如何解决?为了使 Snappy PDF 正常工作,我缺少什么?

4

1 回答 1

0

您需要启用外部链接支持选项。

return \PDF::loadView('yourfile')
      ->setOption('disable-external-links', false)
      ->setOption('enable-local-file-access', true)
      ->setOption('enable-internal-links' , true)

或者

还有另一个具有更多配置的软件包,例如Laravel Dompdf。您可以使用“enable_remote = true”配置添加外部链接。

于 2021-02-18T05:54:28.150 回答