Reputation: 51
I want to generate a PDF with the class Html2pdf in my drupal Module :
Here is my code :
$tab="<table>
<tr>
<td>Salut!</td>
</tr>
</table>
";
try {
$pdf=new HTML2PDF("P","A4","fr");
$pdf->pdf->setDisplayMode("fullpage");
$pdf->writeHTML($tab);
$pdf->output("test.pdf");
} catch (HTML2PDF_exception $e) {
die($e);
}
I have this error : TCPDF ERROR: Some data has already been output, can't send PDF file !!
Upvotes: 1
Views: 547
Reputation: 1101
try {
$pdf=new HTML2PDF("P","A4","fr");
$pdf->pdf->setDisplayMode("fullpage");
$pdf->writeHTML($tab);
$pdf->output("test.pdf");
// Try to add this:
ob_clean();
flush();
// If you want you can add this too:
print $pdf;
drupal_exit();
} catch (HTML2PDF_exception $e) {
die($e);
}
ob_clean();
Discards the contents of the output buffer.
flush();
Flushes the system write buffers of PHP and whatever backend PHP is using (CGI, a web server, etc). This attempts to push current output all the way to the browser with a few caveats.
Make sure you are also using the correct header information:
drupal_add_http_header('Content-Type', 'application/pdf');
Upvotes: 1