编程语言
首页 > 编程语言> > python – WeasyPrint:在每个pdf页面上由长表重叠的固定页脚标记

python – WeasyPrint:在每个pdf页面上由长表重叠的固定页脚标记

作者:互联网

由于WeasyPrint,我用Django生成了一个用pdf渲染的表格.

这个表可能很长(说行数),所以可能会在几页pdf结果中结束.我必须在页面的每一端都包含一个静态页脚,所以我应用了css固定规则.

我的问题是这个页脚与很长的表重叠.我如何要求WeasyPrint(通过我认为css)在每个页脚之前打破表并继续在下一页上呈现表格?

<table>
    <tr></tr> <!-- a lot of rows, potentially spreading on several A4 pages -->
</table>

<footer style="position: fixed"> <!-- footer contents will be repeated and overlapped on each page until </table> is not reached -->

</footer>

我尝试使用css规则作为padding-bottom应用于表标记但没有成功

谢谢

解决方法:

我找到了解决方案.

首先,您要定义页边距:

@page {
    size: A4;
    margin: 15mm 20mm;
}

我有一个顶级&底边距15mm.

当你现在在页面/正文中放置一个固定的页脚时,它将在“内部”这些边距,而非固定元素将与它重叠.所以你想要做的是将固定页脚移动到这些边距的“外部”:

footer
{
    position        : fixed;
    right           : 0;
    bottom          : 0;
    margin-bottom   : -10mm;
    height          : 10mm;
    text-align      : right;
    font-size       : 10px;
}

固定和底部属性将页脚放在底部的每个页面上,但是在定义的边距内(重叠的位置).高度指定页脚高度,然后通过负边距底部属性在边距“外”移动.只需确保margin-bottom> = height.

干杯
多米

标签:python,css,pdf,formatting,weasyprint
来源: https://codeday.me/bug/20190528/1170456.html