dompdf 页脚不起作用?

发布于 2024-10-17 11:22:24 字数 1332 浏览 6 评论 0原文

我正在修改 dompdf 输出脚本以添加页脚。我阅读了 dompdf 本身关于如何执行此操作的教程,但它似乎对我不起作用。

我首先使用 fopen 编写 PDF 正在读取的 HTML 文件。我按照 dompdf 上的说明进行操作,并将其放入标题中:

<script type="text/php">

if ( isset($pdf) ) {

  $font = Font_Metrics::get_font("helvetica", "bold");
  $pdf->page_text(72, 18, "Header: {PAGE_NUM} of {PAGE_COUNT}", $font, 6, array(0,0,0));

}
</script>

但是,它没有在任何地方添加任何类型的文本。这是正在发生的事情的要点。

Page 使用 fopen 和 fwrite (w+) 来编写 HTML 表格和前面提到的页眉/页脚脚本。

$somecontent = "blah blah + previous javascript";
 if (!$handle = fopen($filename, 'w+')) {
              echo "Cannot open file ($filename)";
              exit;
          } //if (!$handle = fopen($filename, 'w+'))
          // Write $somecontent to our opened file.
          if (fwrite($handle, $somecontent) === false) {
              echo "Cannot write to file ($filename)";
              exit;
          } //if (fwrite($handle, $somecontent) === false)
          //echo "Success, wrote ($somecontent) to file ($filename)";
          //echo "Success!";
          fclose($handle);

它在 dompdf 目录中创建一个文件。

单击打印 pdf 链接时,dompdf 会读取创建的 html 文件,并创建 PDF。

我做错了什么吗?我真的很想让页脚在 domdpf 解析的所有页面上工作。

谢谢!

编辑:哦,我还应该提到,我正在使用默认的 dompdf.php 文件将 HTML 文件实际保存为 PDF。并且 DOMPDF_ENABLE_PHP 设置为 true。

I'm working on modifying my dompdf output script to add footers. I read the tutorial from dompdf itself on how to do this, but it doesn't seem to be working for me.

I'm first writing the HTML file that the PDF is reading from using fopen. I followed the instructions on dompdf and put this in the header:

<script type="text/php">

if ( isset($pdf) ) {

  $font = Font_Metrics::get_font("helvetica", "bold");
  $pdf->page_text(72, 18, "Header: {PAGE_NUM} of {PAGE_COUNT}", $font, 6, array(0,0,0));

}
</script>

However, it didn't add any sort of text anywhere. Here's the gist of what is happening.

Page uses fopen and fwrite (w+) to write HTML tables and the aforementioned header/footer script.

$somecontent = "blah blah + previous javascript";
 if (!$handle = fopen($filename, 'w+')) {
              echo "Cannot open file ($filename)";
              exit;
          } //if (!$handle = fopen($filename, 'w+'))
          // Write $somecontent to our opened file.
          if (fwrite($handle, $somecontent) === false) {
              echo "Cannot write to file ($filename)";
              exit;
          } //if (fwrite($handle, $somecontent) === false)
          //echo "Success, wrote ($somecontent) to file ($filename)";
          //echo "Success!";
          fclose($handle);

It creates a file in the dompdf directory.

When the print pdf link is clicked, dompdf reads the html file that was created, and creates the PDF.

Is there something I'm doing wrong? I'd really like to get the footer working on all pages that domdpf parses.

Thanks!

EDIT: Oh, I should also mention that I'm using the default dompdf.php file for actual saving of the HTML files as PDFs. And DOMPDF_ENABLE_PHP is set to true.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

要走就滚别墨迹 2024-10-24 11:22:24

确保脚本包含在 HTML 文档的正文中。 dompdf 当前不处理正文之外的脚本。我相信,如果您没有显式定义 HTML 结构(html/head,body),那么将会创建一个 HTML 结构,并且您的脚本将放置在 head 中。尝试:

$somecontent = "<body>javascript + blah blah</body>";

Make sure the script is contained in the body of the HTML document. dompdf doesn't currently process scripts that are outside the body. I believe that if you do not explicitly define the HTML structure (html/head,body) then one will be created and your scripts will be placed in the head. Try:

$somecontent = "<body>javascript + blah blah</body>";
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文