我有使用 laravel 运行的 PHP 元素。这个想法非常基本:我只想使用 DOM PDF 从数据库生成 PDF。我已经在 View 中包含了 CSS 来设置显示。只显示一页,效果很好。但是当我生成不止一页(分页)时,显示就乱七八糟了。似乎数据相互重叠。我不确定这里发生了什么,但我认为问题出在我的样式 CSS 中。请帮忙!
附言。我设置我的 PDF 页面方向:横向和纸张:f4
<style>
.page-break {
page-break-after: always;
}
body {
font-family: Arial;
}
.split {
height: 100%;
width: 45%;
position: fixed;
z-index: 1;
top: 0;
overflow-x: hidden;
padding-top: 20px;
}
.left {
left: 0;
background-color: none;
}
.right {
right: 0;
background-color: none;
}
.centered {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
text-align: center;
}
.centered img {
width: 150px;
border-radius: 50%;
}
</style>
<body>
<?php
foreach($query as $query){
?>
//to split page left and right
<div class="split left">
<div class="centered">
<h2>{{$query->full_name}}</h2>
<p>Some text.</p>
</div>
</div>
<div class="split right">
<div class="centered">
<h2>{{$query->full_name}}</h2>
<p>Some text here too</p>
</div>
</div>
//page break
<div class="page-break"></div>
<?php }?>
</body>
最佳答案
尝试将此代码添加到您的 Blade 文件中
<div style="page-break-after:always;">
</div>
关于php - 如何从带有分页符的表格中正确生成PDF,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55917602/