I will start out by saying that I can generate PDFs just fine with mPDF, but for the life of me, I can\'t get it to merge an existing PDF with the PDF it just generated.
This code is work with mpdf 8.0.7 with php 7.4.
Mfiles = array();
//Multiple pdf store in Mfiles array with full path.
array_push($Mfiles,'/assets/'.$pdfname.'.pdf');
$Mpath = 'Give file path with have you need to merge all pdf';
// after loop we start this code
if($Mfiles)
{
$filesTotal = sizeof($Mfiles);
$fileNumber = 1;
if (!file_exists($Mpath))
{
$handle = fopen($Mpath, 'w');
fclose($handle);
}
foreach ($Mfiles as $fileName)
{
if (file_exists($fileName))
{
$pagesInFile = $pdf->SetSourceFile($fileName);
for ($i = 1; $i <= $pagesInFile; $i++)
{
$tplId = $pdf->importPage($i);
$pdf->UseTemplate($tplId);
if (($fileNumber < $filesTotal) || ($i != $pagesInFile))
{
$pdf->WriteHTML(' ');
}
}
}
$fileNumber++;
}
$pdf->Output($Mpath);
}