如何使用DOMPDF正确分解文档? [英] How I can break my document correctly with DOMPDF?
问题描述
我想通过动态内容生成一个带有DOMPDF的PDF。我创建了一个这样的表:
I want to generate a PDF with DOMPDF through dynamic content. I am creating a table like this:
<?php
$language = $this->input->cookie('language');
if (!isset($language))
{
$language = $core_settings->language;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta name="Author" content=""/>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="invoice.css" type="text/css" charset="utf-8" />
<style type="text/css">
@page {
margin: 0;
}
.pages {
margin: .5in;
}
.other-pages{
padding:60px;
}
.first-page {
margin: 0in;
background-color: black;
height: 100%;
width: 100%;
position:absolute;
background-image: url('https://www.example.com/wp-content/uploads/2015/09/example-cover1.jpg');
background-position: bottom center;
background-repeat: no-repeat;
background-size: 100%;
}
.first-page + * {
page-break-before: always;
}
</style>
</head>
<body>
<div class="pages first-page"></div>
<div class="other-pages">
<h2>Title</h2>
<div class="round">
<table id="table" class="tablesorter" cellspacing="0">
<thead>
<tr class="header">
<th width="5%">#</th>
<th width="95%">Tarea</th>
</tr>
</thead>
<tbody>
<?php $i = 0; $sum = 0; $row=false; ?>
<?php foreach ($tasks as $task):?>
<tr <?php if($row){?>class="even"<?php } ?>>
<td><?php echo $i; ?></td>
<td><?php echo $task->name; ?><br><?php echo strip_tags($task->description); ?></td>
</tr>
<?php $i++; endforeach; $row = true; ?>
</tbody>
</table>
</div>
</div>
</body>
</html>
当我生成PDF时,我有这样的:
When I generate the PDF I have like this:
- 封面(无页边)
- 动态内容
- 动态内容表(与
始终相同)
- COVER PAGE (without margin)
- TABLE WITH DYNAMIC CONTENT
- FULL BLANK PAGE (The problem)
- TABLE WITH DYNAMIC CONTENT (it's the same table always)
我可以修复空白页吗?
注意:我的表的内容取决于内容,所以高度取决于内容,我不能支持X字段和断页。
NOTE: The content of my table depends of the content, so the height depends of the content, I cannot supose X fields and break page.
推荐答案
当dompdf在页面上分割内容时,会复制元素上的样式。这意味着以下样式被复制到split元素,导致分页:
When dompdf splits content across pages it duplicates the styling on the element. That means the following style is copied to the split element, causing a page break:
.first-page + * {
page-break-before: always;
}
由于您只想在第一页后使用分页符,
Since you just want a page break after the first page use the following instead:
.first-page {
page-break-after: always;
}
已记录与此问题相关: page-break-before应用于long元素时的分页符加倍
这篇关于如何使用DOMPDF正确分解文档?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!