我想通过动态内容生成带有DOMPDF的PDF。我正在创建一个这样的表:
<?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时,我喜欢这样:
如何修复空白页?
注意:我的表格内容取决于内容,因此高度取决于内容,我不能使用X字段和分页。
答案 0 :(得分:0)
当dompdf在页面之间拆分内容时,它会复制元素上的样式。这意味着以下样式被复制到split元素,导致分页:
.first-page + * {
page-break-before: always;
}
由于您只想在第一页后使用分页符,所以请改为使用以下内容:
.first-page {
page-break-after: always;
}
至少有一个与此问题相关的问题:"doubling" of page breaks when page-break-before applied to long element