You can keep your current file, but instead of something like this:
...
foreach ($htmldoc_collection as $htmldoc) {
$dompdf = new DOMPDF();
$dompdf->load_html($htmldoc);
$dompdf->render();
$pdfdata=$dompdf->output();
file_put_contents("../pdf/".$fileName.".pdf", $pdfdata);
unset($dompdf);
}
...
you would do something like this:
...
foreach ($htmldoc_collection as $htmldoc) {
file_put_contents("doc.html", $htmldoc);
exec("php pdfgen.php doc.html $filename");
unlink("doc.html");
}
...
pdfgen.php would look something like this:
$htmldoc = $argv[1];
$filename = $argv[2];
$dompdf = new DOMPDF();
$dompdf->load_html_file($htmldoc);
$dompdf->render();
file_put_contents($fileName, $dompdf->output());
Modify the above as necessary to get things working how you want, it may take some trial-and-error.