php - Laravel dompdf 不显示为视图
问题描述
我正在尝试生成书籍封面,在我的刀片视图中看起来不错,但是当我生成 pdf 时,它看起来不像预览
书前预览
PDF 生成
我的刀片视图:
<!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');
解决方案
嗨 Ramiro,这可能无法真正解决您的问题,但它肯定会帮助您了解正在发生的事情。
根据https://github.com/barryvdh/laravel-dompdf,我想您可能应该将您的 pdf 方向更改为水平以捕获更多屏幕区域。
我发现很难理解为什么图书馆拒绝捕获整个屏幕而不管方向如何,它就像它针对特定的视口左右,或者可能是因为它是一个图像?好吧,这在文档中没有详细说明。
以下是我能够实现的目标,它非常接近您想要的,并且您可能会喜欢它以节省时间。
刀片示例代码:
<!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示例代码:
function returnView(){
$data = [
'owner'=>"Ramiro",
'title'=>"StackOverflow"
];
$path = "/qrcodes/"."stackoverflow.pdf";
$pdf = PDF::loadView('email.sample', $data)->setPaper('letter', 'landscape')->save(public_path($path));
return $pdf->stream("Halloa.pdf");
//return view('email.sample', $data);
}
注意:负边距实际上并不重要,没有它仍然会很好看。
推荐阅读
- sql - 像 postgresql 数据问题中的运算符条件
- java - 如何在 ARCore Sceneform 中为节点创建动画(更改缩放、旋转或位置)?
- android - 应用程序关闭时将文件传输到 Amazon S3
- python - 自动化运行脚本文件的数量定义文件使用 python
- c# - 在指定字符串周围返回 html 标记的 Reqex 模式
- json - Azure 逻辑应用:从文件中读取 XML 并使用数据写入 JSON
- c# - 如何比较两个列表并返回 4 个类别列表
- actions-on-google - 通过语音调用时,conv.user.storage 值不会跨会话保存
- video-streaming - Wowza 流媒体引擎集群?
- regex - 为什么正则表达式在可选字符后输入 1 个字母时不起作用?