Wordpress主题php到pdf转换错误

Wordpress theme php to pdf conversion error

我正在使用 WordPress 作为我的 CMS.So 有一部分我试图从 php 生成 pdf 文件。我正在使用 phpToPDF 生成 pdf file.I 在 wordpress 的自定义模板页面中这样做,但出现此错误:


Warning: Cannot modify header information - headers already sent by (output 
started at /Applications/MAMP/htdocs/Wordpress/wp-includes/general-
template.php:2942) in /Applications/MAMP/htdocs/Suburban/wp-
content/themes/custom theme/phpToPDF.php on line 56

尝试从核心 php 生成 pdf 并且成功了... 但是我的 wordpress 站点需要它。

这是代码


<?php 
/* Template Name:test */
wp_head(); 
require("phpToPDF.php");

  $my_html="<div style=\"display:block;\">
  <div style=\"float:left; width:33%; text-align:left;\">
         Left Header Text
  </div>
  <div style=\"float:left; width:33%; text-align:center;\">
         Center Header Text
  </div>
  <div style=\"float:left; width:33%; text-align:right;\">
       Right Header Text
   </div>
   <br style=\"clear:left;\"/>
</div>";

   $pdf_options = array(
    "source_type" => 'php',
    "source" => $my_html,
    "action" => 'view',
    "save_directory" => '',
    "file_name" => 'pdf_test.pdf');
   phptopdf($pdf_options);

  // echo ("<a href='pdf_invoice.pdf'>Download Your PDF</a>");  
 wp_footer()
  ?>

删除wp_head(); wp_footer() 修复了这个错误