Html 如何使用DOMPDF正确断开文档?
我想通过动态内容生成带有DOMPDF的PDF。我正在创建一个如下表:Html 如何使用DOMPDF正确断开文档?,html,css,dompdf,html-to-pdf,Html,Css,Dompdf,Html To Pdf,我想通过动态内容生成带有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://w
<?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>
@页面{
保证金:0;
}
.页{
边缘:.5英寸;
}
.其他网页{
填充:60px;
}
.第一页{
边距:0英寸;
背景色:黑色;
身高:100%;
宽度:100%;
位置:绝对位置;
背景图像:url('https://www.example.com/wp-content/uploads/2015/09/example-cover1.jpg');
背景位置:底部中心;
背景重复:无重复;
背景大小:100%;
}
.第一页+*{
前分页符:始终;
}
标题
#
跗骨
>
当我生成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>
注意:我的表格的内容取决于内容,因此高度取决于内容,我不能使用X字段并断开页面。当dompdf将内容拆分为多个页面时,它会在元素上复制样式。这意味着将以下样式复制到拆分元素,从而导致分页符:
.first-page + * {
page-break-before: always;
}
由于您只希望在第一页之后使用分页符,请改用以下命令:
.first-page {
page-break-after: always;
}
至少记录了一个与此问题相关的问题:Hi@BrianS感谢您的回复,我尝试了您所说的,但它不起作用。您的更改如下:空白页(完全空白页)封面页(背景图像,在同一图像的背景中,有动态表格页的第一部分)动态表格页当我使用您的示例进行测试时,它看起来与预期一样,但我无法访问invoice.css,因此可能会有一些其他样式影响布局。您可能需要调整
。第一页的高度。dompdf并不总是像您所期望的那样处理100%页面高度的元素。您好,BrianS,我按照您所说的那样尝试(没有invoice.css),但不起作用,事实上,我需要的只是在第一页中放置一个背景图像,边距为0,然后我想打印一个带有边距的大型动态表,但是谢谢你的帮助=)使用建议的编辑PDF。查看脚本生成的实际HTML可能会有所帮助。