gpt4 book ai didi

php - 如何使用dompdf打印页码并将页面边框设置为pdf

转载 作者:太空宇宙 更新时间:2023-11-04 11:26:43 25 4
gpt4 key购买 nike

我目前正在使用 wrapper of dompdf让 laravel 生成我的 pdf,但我想打印页码并在页面上添加边距,我该怎么做?

我已经尝试过但没有成功:

@page {

margin: 0.5in 0.25in;

}

最佳答案

您的 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>

当前不工作。因此,我们必须通过定义页边距并在该页边距内放置一个框架元素来解决这些问题:

@page { margin: 2.5in; }
.page-border { position: fixed; left: -2.5in; top: -2.5in; bottom: -2.5in; right: -2.5in; border: 2in solid orange; }
<!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>

显示当前页码只需要一点 CSS:

.page-number:before  {
content: counter(page);
}
<!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>

关于php - 如何使用dompdf打印页码并将页面边框设置为pdf,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32324086/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com