我有使用laravel运行的PHP项目。这个想法非常基础:我只想从包含DOM PDF的数据库中生成PDF。我已经在视图中包含CSS来设置显示。仅显示一页,效果很好。但是当我生成多个页面(分页符)时,显示混乱了。似乎数据相互重叠。我不确定这里发生了什么,但是我认为问题出在我的CSS样式上。请帮忙!
PS。我将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>
答案 0 :(得分:0)
尝试将此代码添加到刀片文件中
<div style="page-break-after:always;">
</div>
答案 1 :(得分:0)
我也面临着同样的问题。我找到了解决方案,请检查以下代码。对于DOM PDF,html格式安排如下
<html>
<head>
<style>
@page { margin: 20px 50px 50px;
@top-center {
content: element(header);
}
@bottom-left {
content: element(footer);
}
}
div.header {
display: block;
top:0; left:0; right:0;
width:100%;
position:fixed;
}
div.footer {
display: block;
padding: 5px;
position: running(footer);
width:100%;
clear:both;
}
div.content {
width: 100%;
}
</style>
</head>
<body>
<div class='header'>Header</div>
<div class='footer'>Footer</div>
<div class='content'>Content</div>
</body>
</html>
我认为这种解决方案很适合您。