【发布时间】:2016-09-23 18:38:24
【问题描述】:
我正在使用 dompdf 生成我想用各种不同公司的品牌纸标记的字母。为此,我通过 css 获取背景图像。请参阅底部的示例图像。然后我设置适当的边距以适应我想写出的内容到空白处。但是我只希望这个信头只显示在第一页上。目前它正在重复到每一页。我的 CSS 看起来像:
<html>
<head>
<meta charset="utf-8">
<title>{$pdf.title}</title>
<style type="text/css">
@page {
size: A4;
margin:0;
padding: 0;
}
body {
padding: {$branding.page_margin_top}cm {$branding.page_margin_right}cm {$branding.page_margin_bottom}cm {$branding.page_margin_left}cm;
font-size: 7pt;
font-family: helvetica !important;
background-image: url('{$base_url}pd-direct.png');
background-position: center center;
background-repeat: no-repeat;
font-size: 10pt;
}
#postal-address {
margin: 0cm;
margin-left: {$branding.address_offset_left}cm;
margin-top: {$branding.address_offset_top}cm;
margin-bottom: {$branding.address_offset_bottom}cm;
font-size: 10pt;
}
#date {
font-weight: bold;
}
</style>
</head>
<body>
<div id="page-body">
<div id="content">
{if $pdf.postal_address}
<div id="postal-address">
{$pdf.postal_address|nl2br}
</div>
{/if}
{$pdf.main_body}
</div>
</div>
</body>
</html>
如何更改此设置,使背景图像仅显示在 dompdf 输出的第一页上?
查看当前正在呈现的 html:http://eclecticgeek.com/dompdf/debug.php?identifier=ccfb2785f8a8ba3e1e459cbd283ad015
【问题讨论】:
-
你试过
@page :first吗?据我所知,它适用于 wkhtmltopdf - 我不确定它是否适用于 dompdf。 -
background-image 似乎无法在使用 dompdf 的 @page 上工作。
-
在发布我建议
@page :first的答案之前没有看到这些cmets!您能否提供一些 PHP 代码,以便人们可以更轻松地进行剪切/粘贴测试? -
@miken32 “在发布我建议“@page”的答案之前没有看到这些 cmets:first”是什么意思?我说背景图像不适用于 dompdf 上的“@page”。发布 PHP 代码无济于事,因为这里的问题是 HTML CSS 而不是 PHP。我发布了一个指向使用 dompdf 调试工具呈现的当前 HTML 的链接:eclecticgeek.com/dompdf/…
-
我的意思是我发布了一个建议
@page :first的答案,然后将其删除。