Wkhtmltopdf 页脚未随位置呈现

Rém*_*V.D 5 html css pdf wkhtmltopdf

在我的 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>
Run Code Online (Sandbox Code Playgroud)

当未指定位置时它会起作用...

为了生成 pdf,我使用 pdfkit 和 python:

pdfkit.from_file(content_url, 'out.pdf', {        
        '--footer-html': footer_url,
        '--footer-spacing':  '10'
    })
Run Code Online (Sandbox Code Playgroud)

这是我在 content_url 中使用的内容

<!DOCTYPE html>
<html>

<head>

</head>

<body>
<p> content </p>
</body>

</html>
Run Code Online (Sandbox Code Playgroud)

有什么帮助吗?

Mar*_*chi 5

您需要在页脚 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>
Run Code Online (Sandbox Code Playgroud)

在 wkhtmltopdf 0.12.4(带有修补的 qt)上测试。