I’m currently trying to use HTML2PDF (PHP Helper) to generate a HTML PDF with a Plugin. The Plugin is just a simple shortcode, to activate it. However, When i the function is activated (shortcode detected) I get an headers already sent message. I do understand that this means PHP has already set the header information.
But how can i fix this? so the plugin will generate an PDF.
Plugin code
require_once('html2pdf/html2pdf.class.php');
add_shortcode('generate_pdf', 'pdf_saving');
function pdf_saving()
{
$content_html = "<h1>Hello</h1>";
$html2pdf = new HTML2PDF('P', 'A4', 'en');
$html2pdf->pdf->SetDisplayMode('fullpage');
$html2pdf->writeHTML($content_html);
// ob_clean(); I've also tried this.
$html2pdf->Output('file.pdf');
}
Error message,
TCPDF ERROR: Some data has already been output, can’t send PDF file
You try below code