【发布时间】:2018-06-16 04:41:43
【问题描述】:
我使用 WordPress 作为我的 CMS。所以有一部分我正在尝试从 php 生成 pdf 文件。我正在使用 phpToPDF 生成 pdf 文件。我在 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()
?>
【问题讨论】:
-
没什么帮助
-
首先删除 php "?>" 的结束标签。如果没有帮助,则从这部分提供功能 "Applications/MAMP/htdocs/Suburban/wp- content/themes/custom主题/phpToPDF.php 第 56 行"
-
如何“从这部分提供功能”Applications/MAMP/htdocs/Suburban/wp-content/themes/custom theme/phpToPDF.php on line 56”?它包含这行代码“标题('Content-type: application/pdf');"
标签: php wordpress wordpress-theming fpdf php-pdftk