使用PHP中的DOMPDF的PDF页面中的页眉 [英] Header in PDF page using DOMPDF in PHP

查看:504
本文介绍了使用PHP中的DOMPDF的PDF页面中的页眉的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用DOMPDF创建PDF文件.我有大量要提取的PDF内容,我们在所有页面中都需要一些标题.因此,任何人都可以telme如何在PDF中添加页眉和页脚,以便使用DOMPDF在所有页面中显示页眉.

I am creating a PDF file using DOMPDF. I have a big content to extract in PDF, we need some header in all the pages. So can anyone telme how to add a header and footer in the PDF so that the header will shown in all the pages using DOMPDF.

推荐答案

在0.6.0代码中,您将能够使用HTML + CSS生成页眉和页脚.与使用嵌入式PHP相比,存在一些限制(例如,尚无PAGE_COUNT占位符),因此这是否可行取决于您的需求.

In the 0.6.0 code you will be able to use HTML+CSS to generate headers and footers. There are a few limitations when compared to using inline PHP (e.g. no PAGE_COUNT placeholder yet), so whether or not this is viable depends on your needs.

以下代码将生成包含页眉和页脚的两页文档:

<html>
<head>
  <style>
    @page { margin: 180px 50px; }
    #header { position: fixed; left: 0px; top: -180px; right: 0px; height: 150px; background-color: orange; text-align: center; }
    #footer { position: fixed; left: 0px; bottom: -180px; right: 0px; height: 150px; background-color: lightblue; }
    #footer .page:after { content: counter(page, upper-roman); }
  </style>
<body>
  <div id="header">
    <h1>Widgets Express</h1>
  </div>
  <div id="footer">
    <p class="page">Page </p>
  </div>
  <div id="content">
    <p>the first page</p>
    <p style="page-break-before: always;">the second page</p>
  </div>
</body>
</html>

如果需要访问某些缺少的功能,也可以将两种样式结合使用.使用page_text方法添加的PDF对象和文本将呈现在HTML内容的顶部.

You could also use a combination of the two styles if you needed access to some of the missing functionality. PDF objects and text added using the page_text method render on top of the HTML content.

这篇关于使用PHP中的DOMPDF的PDF页面中的页眉的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆