I am using WordPress as my CMS.So there is a part where I am trying to generate a pdf file from php. I am using phpToPDF for generating the pdf file.I am doing so in a custom template page of wordpress and but getting this error:
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
Tried to generate the pdf from core php and it worked... But I need it in my wordpress site.
here is the code
<?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()
?>
Removing wp_head(); and wp_footer() fixed this error