i have a file which generates html and adds it to a php String using buffer
<?php ob_start(); ?>
<table>
<tr>
<td>Content</td>
</tr>
</table>
<?php
$contents = ob_get_contents();
ob_flush();
mail($to, $subject, $contents, $headers);
?>
Is there a way to save the contents of the string as a pdf file on the server using php?
I have tried using FPDF but it does not work since the content is at the top of the page and i get a output error from fpdf.
Any help appreciated
You need to use
ob_end_clean()instead ofob_flush();ob_flush();will print the html and you don’t want that. As FPDF creates a pdf and needs to manipulate the headers (to be a pdf). If you echo/print something first php will automatically set default header. The library can’t modify them once they are set resulting in error.after you have put the content of the ob in a var (
$contents = ob_get_contents();) you can useob_end_clean(). This will discard the content of the buffer and stop buffering.