我目前正在使用wrapper of dompdf来生成我的pdf文件,但我想打印页码并为页面添加页边距,我该怎么办?
我试过这个没有成功:
@page {
margin: 0.5in 0.25in;
}
答案 0 :(得分:0)
您的CSS应在页面边缘和文档正文之间的页面周围设置边距。如果您想要的是以某种方式(CSS定义的边框)设置该空间的样式,您通常会尝试以下内容:
@page { margin: 0in; }
body { padding: .5in; border: 2in solid orange; }

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
</head>
<body>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</body>
</html>
&#13;
目前没有工作。因此,我们必须通过定义页边距并在该边距内放置框架元素来解决这些问题:
@page { margin: 2.5in; }
.page-border { position: fixed; left: -2.5in; top: -2.5in; bottom: -2.5in; right: -2.5in; border: 2in solid orange; }
&#13;
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
</head>
<body>
<div class="page-border"></div>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</body>
</html>
&#13;
显示当前页码只需要一点CSS:
.page-number:before {
content: counter(page);
}
&#13;
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
</head>
<body>
<p>Current Page: <span class="page-number"></span></p>
</body>
</html>
&#13;