i have a .php page with connection to a MySql BD to read some information and then I want to convert it to PDF to print the page. My question is, may I use DomPdf ? Or it only work for only html code? Thank you!
You can use dynamic data like this. change fields in $html dynamically.
$html = "<table border='1' width='100%' style='border-collapse: collapse;'>
<tr>
<th>Username</th><th>Email</th>
</tr>
<tr>
<td>yssyogesh</td>
<td>yogesh@makitweb.com</td>
</tr>
<tr>
<td>sonarika</td>
<td>sonarika@gmail.com</td>
</tr>
<tr>
<td>vishal</td>
<td>vishal@gmail.com</td>
</tr>
</table>";
// include autoloader
require_once 'dompdf/autoload.inc.php';
// reference the Dompdf namespace
use Dompdf\Dompdf;
// instantiate and use the dompdf class
$dompdf = new Dompdf();
$dompdf->loadHtml($html);
// (Optional) Setup the paper size and orientation
$dompdf->setPaper('A4', 'landscape');
// Render the HTML as PDF
$dompdf->render();
$output = $dompdf->output();
file_put_contents("file.pdf", $output);