gpt4 book ai didi

css - DOMPDF 分页符

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

我正在尝试生成包含页眉、页脚和内容的报告。页眉和页脚工作正常,但是内容 div 的文本比我想要的高。 See the image .我真的不明白为什么页面会这么高。

这是 CSS 代码:

@page { 
margin: 180px 50px;
}

#header {
position: fixed;
left: 0px;
top: -150px;
right: 0px;
height: 150px;
text-align: left;
}

#footer {
position: fixed;
left: 0px;
bottom: -180px;
right: 0px;
height: 80px;
text-align: right;
background-color: lightblue
}

#footer .page:after {
content: counter(page, upper-roman);
}

#content {
padding-left: 10mm;
padding-right: 5mm;
line-height: 6mm;
background-color: lightgreen;
height: 850px;
}
#logo {
height: 4cm;
}
#head_text {
display: inline-block;
line-height: 6mm;
padding-top: 15px;
}

这是 HTML:

<html>
<head>
<style>
'.$css.'
</style>
</head>
<body>

<div id="header">
'.$header.'
</div>

<div id="footer">
<p class="page">Página </p>
</div>

<div id="content">
'.$content.'
</div>

</body>
</html>

谁能帮忙解决这个问题?坦克!

最佳答案

如果您的 DOMPDF_DPI 设置为 72,那么 180 像素的边距就相当大了。 72 的 DPI 提供从 PX 到 PT(PDF 中的 native 单位)的一对一转换。 dompdf 生成的 PDF 文档始终为 72 PPI。这相当于内容周围有 2.5 英寸的边距。我不认为你打算那么多地填补你的利润。

我看到的另一个问题是您在内容元素上设置了高度条件。你并不真的需要这个,我看到它在我运行一些测试渲染时引起了一些问题。如果您希望内容背景具有特定颜色,那么我建议将其设置在 body 元素上,这是文档内容的真正边界。

尝试以下操作:

@page { 
margin: 180px 50px;
}
#header {
position: fixed;
left: 0px;
top: -150px;
right: 0px;
height: 150px;
text-align: left;
}

#footer {
position: fixed;
left: 0px;
bottom: -180px;
right: 0px;
height: 80px;
text-align: right;
background-color: lightblue
}

#footer .page:after {
content: counter(page, upper-roman);
}

body {
background-color: lightgreen;
height: 850px;
}
#content {
padding-left: 10mm;
padding-right: 5mm;
line-height: 6mm;
}
#logo {
height: 4cm;
}
#head_text {
display: inline-block;
line-height: 6mm;
padding-top: 15px;
}
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
</head>
<body>
<div id="header">
HEADER
</div>

<div id="footer">
<p class="page">Página </p>
</div>

<div id="content">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus id erat blandit, auctor massa eu, aliquam lacus. Suspendisse justo ante, gravida vel diam quis, porta luctus nisi. Donec id enim sem. Sed et lobortis magna. Ut et dignissim augue. Cras quam libero, feugiat ac auctor eget, semper a augue. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Suspendisse quis hendrerit ex. Phasellus auctor dolor sit amet nibh rhoncus sagittis. Sed quis odio sit amet purus feugiat malesuada.</p>
</div>
</body>
</html>

关于css - DOMPDF 分页符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34634091/

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