我正在使用dompdf生成一个报告。并尝试在一个页面中重复一个元素,根据数据的不同,它可能需要4个页面。但它只在第一页创建
目前我有这个html标记。
<html>
<head>
<style>
@page {
margin: .5in;
}
.footer{
position:fixed;
width:100%;
bottom:60px;
}
.page-3{
position:relative;
}
.repeat{
position:fixed;
width:100%;
top:10px;
}
</style>
</head>
<body>
<div class="page page-1">
<div class="content">
<div class="content-header">...</div>
<div class="content-text">...</div>
</div>
</div>
<div class="page page-2">
<div class="content">
<div class="content-header">...</div>
<div class="content-text">...</div>
</div>
</div>
<div class="page page-3">
<div class="content">
<div class="content-header repeat">
This must repeat in all pages generated
</div>
<div class="content-text">
atleast 2~4 pages
</div>
</div>
</div>
<div class="page page-4">
<div class="content">
<div class="content-header">...</div>
<div class="content-text">...</div>
</div>
</div>
<div class="footer">
footer
</div>
</body>
</html>
假设.page-3
生成了3个页面。但是.repeat
只出现在.page-3
的第一个页面上
我尝试使用.page-3
的背景图像,但它仍然是相同的,并且只在第一个生成的页面上显示。
我使用的是dompdf的0.8.2
版本。
发布于 2018-08-13 08:17:51
如果有人和我有同样的问题。我最终使用的是page_script
。
因为我知道前两个页面是静态的,最后一个页面是静态的,所以我访问了$PAGE_NUM
并设置了如下条件
`
$pdf->page_script('
if( $PAGE_NUM != 1 ){ // 1st page has no header
$text = "";
if( $PAGE_NUM == 2 ){
$text = "This is 2nd page";
}else if( $PAGE_NUM > 2 && $PAGE_NUM < $PAGE_COUNT ){
$text = "This is the page 3 until before the last page";
}else if( $PAGE_NUM == $PAGE_COUNT ){
$text = "This is last page";
}
// setup postioning, color, size etc for design
// use $text as header text
$pdf->text( $posX, $posY, $text, $font, $size, $color);
}
');
`
并删除了HTML标记中的所有<div class="content-header">...</div>
https://stackoverflow.com/questions/51799133
复制相似问题