使用 barryvdh/laravel-dompdf 在每一页上重复标题

发布时间:2021-02-25 08:48

我有问题要在每一页上重复页眉 使用 Dompdf Wrapper for Laravel。任何人都可以帮忙举个简单的例子吗?

回答1

这是基本示例,但我想您可以进一步探索以符合您的要求。

<style>
/** Define now the real margins of every page in the PDF **/
body {
    margin-top: 2cm;
    margin-left: 2cm;
    margin-right: 2cm;
    margin-bottom: 2cm;
}

/** Define the header rules **/
header {
    position: fixed;
    top: 0cm;
    left: 0cm;
    right: 0cm;
    height: 2cm;
    /** Extra personal styles **/
    background-color: #eaeaea;
    color: black;
    text-align: center;
    line-height: 1.5cm;
}

/** Define the footer rules **/
footer {
    position: fixed;
    bottom: 0cm;
    left: 0cm;
    right: 0cm;
    height: 2cm;

    /** Extra personal styles **/
    background-color: #eaeaea;
    color: black;
    text-align: center;
    line-height: 1.5cm;
}
footer .pagenum:before {
    content: counter(page);
}
</style>

在 Body Tag 中添加 HEADER 和 FOOTER 标签,并将主要内容包裹在 main 标签中

<header>
    This is a header
</header>

<footer>
<div class="pagenum-container">Page <span class="pagenum"></span></div>
</footer>
<main>
    <div>Main content goes here </div>
</main>

参考站点 - https://ourcodeworld.com/articles/read/687/how-to-configure-a-header-and-footer-in-dompdf