-2

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()
  ?>
  • 1
    Possible duplicate of [How to fix "Headers already sent" error in PHP](https://stackoverflow.com/questions/8028957/how-to-fix-headers-already-sent-error-in-php) – M0ns1f Jan 06 '18 at 16:30
  • not much helpful – Soumyojyoti Jan 06 '18 at 16:36
  • delete the close tag of php "?>" at first.if that didn't help, then provide function from this part "Applications/MAMP/htdocs/Suburban/wp- content/themes/custom theme/phpToPDF.php on line 56" – Samvel Aleqsanyan Jan 06 '18 at 16:53
  • how to "provide function from this part "Applications/MAMP/htdocs/Suburban/wp- content/themes/custom theme/phpToPDF.php on line 56"? it contains this line of code " header('Content-type: application/pdf');" – Soumyojyoti Jan 06 '18 at 17:21

1 Answers1

0

Removing wp_head(); and wp_footer() fixed this error