首页 > 解决方案 > @page bottom-centre CSS property doesn't repeat for each page when used with running element

问题描述

I'm trying to create a footer for my PDF file generated with HTML. I'm able to create a header that repeats for each page. Strangely enough, when I use the exact same technique to implement the footer, only the last page of the PDF has the footer. I'm doing it like this

@page{
            size: a4 landscape;
            @top-center {
                content: element(header);
            }
            @bottom-center {
                content: element(footer);
            }
            margin-top: 12em;
            margin-bottom: 12em;
            margin-left: 1em;
            margin-right: 1em;
        }
footer {
            position: running(footer);
            text-align: center;
            padding: 5px 5px;
        }
header{
    position: running(header);
}

<footer>
Some text
</footer>

Is this a problem with CSS itself or the HTMLToPDF library I am using? I'm using openHTMLtoPDF Java library. Or is this a problem with me?

标签: htmlcssprintingopenhtmltopdf

解决方案


Making the running element the first element after the body tag solved the problem for me.


推荐阅读