Wkhtmltopdf 页脚不随位置呈现
Wkhtmltopdf footer not rendering with position
在我的 html 中,页脚不会在 pdf 中呈现...
<!DOCTYPE html>
<html>
<head>
<style>
footer{
background:#ccc;
position:absolute;
bottom:0;
width:100%;
padding-top:50px;
}
</style>
</head>
<body>
<footer>
<p> test </p>
<p> test </p>
<p> test </p>
<p> test </p>
<p> test </p>
<p> test </p>
<p> test </p>
<p> test </p>
<p> test </p>
</footer>
</body>
</html>
未指定位置时有效...
为了生成 pdf,我将 pdfkit 与 python:
一起使用
pdfkit.from_file(content_url, 'out.pdf', {
'--footer-html': footer_url,
'--footer-spacing': '10'
})
这是我在content_url
中使用的内容
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<p> content </p>
</body>
</html>
有什么帮助吗?
您需要在页脚上指定主体的高度 html 以使用定位使其可见(就像在其他网页中一样)。
使用下面的代码,您可以获得与页面底部边缘对齐的可变高度页脚。 注意: 调用 wkhtmltopdf 时必须指定下边距,使用 --margin-bottom 选项。
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<style type="text/css">
body {
margin: 0;
padding: 0;
line-height: 1;
font-size: 12pt;
height: 20mm; /* set it to your bottom margin */
}
.footer {
position: absolute;
bottom: 0;
left: 0;
right: 0;
}
</style>
</head>
<body>
<div class="footer">test <b>html</b> footer<br/><i style="color:blue;">two lines</i></div>
</body>
</html>
在 wkhtmltopdf 0.12.4 上测试(带有修补的 qt)。
许多人将边距设置为 0 以在整篇论文中显示 PDF 页面。
这是页脚和页眉出现问题的时候。
您需要在命令中设置选项 * --margin-top 10 --margin-bottom 10 *
或者在 wkhtmltopd 包装器的配置文件中设置它。
这是 snappyBundle(wkhtmltopdf 包装器库)的配置
knp_snappy:
pdf:
enabled: true
binary: '%env(WKHTMLTOPDF_PATH)%'
options:
enable-javascript: true
javascript-delay: 200
no-stop-slow-scripts: true
encoding: 'UTF-8'
margin-top: 10
margin-right: 0
margin-bottom: 10
margin-left: 0
在我的 html 中,页脚不会在 pdf 中呈现...
<!DOCTYPE html>
<html>
<head>
<style>
footer{
background:#ccc;
position:absolute;
bottom:0;
width:100%;
padding-top:50px;
}
</style>
</head>
<body>
<footer>
<p> test </p>
<p> test </p>
<p> test </p>
<p> test </p>
<p> test </p>
<p> test </p>
<p> test </p>
<p> test </p>
<p> test </p>
</footer>
</body>
</html>
未指定位置时有效...
为了生成 pdf,我将 pdfkit 与 python:
一起使用pdfkit.from_file(content_url, 'out.pdf', {
'--footer-html': footer_url,
'--footer-spacing': '10'
})
这是我在content_url
中使用的内容<!DOCTYPE html>
<html>
<head>
</head>
<body>
<p> content </p>
</body>
</html>
有什么帮助吗?
您需要在页脚上指定主体的高度 html 以使用定位使其可见(就像在其他网页中一样)。
使用下面的代码,您可以获得与页面底部边缘对齐的可变高度页脚。 注意: 调用 wkhtmltopdf 时必须指定下边距,使用 --margin-bottom 选项。
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<style type="text/css">
body {
margin: 0;
padding: 0;
line-height: 1;
font-size: 12pt;
height: 20mm; /* set it to your bottom margin */
}
.footer {
position: absolute;
bottom: 0;
left: 0;
right: 0;
}
</style>
</head>
<body>
<div class="footer">test <b>html</b> footer<br/><i style="color:blue;">two lines</i></div>
</body>
</html>
在 wkhtmltopdf 0.12.4 上测试(带有修补的 qt)。
许多人将边距设置为 0 以在整篇论文中显示 PDF 页面。
这是页脚和页眉出现问题的时候。
您需要在命令中设置选项 * --margin-top 10 --margin-bottom 10 * 或者在 wkhtmltopd 包装器的配置文件中设置它。
这是 snappyBundle(wkhtmltopdf 包装器库)的配置
knp_snappy:
pdf:
enabled: true
binary: '%env(WKHTMLTOPDF_PATH)%'
options:
enable-javascript: true
javascript-delay: 200
no-stop-slow-scripts: true
encoding: 'UTF-8'
margin-top: 10
margin-right: 0
margin-bottom: 10
margin-left: 0