I found this library to convert HTML to PDF: dompdf.
The example source code looks like this:
<?php
require_once("dompdf/dompdf_config.inc.php");
$html =
'<html><body>'.
'<p>Put your html here, or generate it with your favourite '.
'templating system.</p>'.
'</body></html>';
$dompdf = new DOMPDF();
$dompdf->load_html($html);
$dompdf->render();
$dompdf->stream("sample.pdf");
?>
Is there a way to import a PHP output into this code?
Or is there a better way to convert a PHP output to PDF?
You can use Output Buffers to achieve this as well. I’ve used this with DOMPDF in the past.
$layoutHTML will have the processed HTML.
And then you can use DOMPDF the way you’ve described in your question
Careful that this can chew a lot of memory (depending on the problem of course).