开发者

dompdf footers not working?

开发者 https://www.devze.com 2023-02-11 10:46 出处:网络
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 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.


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>";
0

精彩评论

暂无评论...
验证码 换一张
取 消