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.
I Merge pdfs like this - {all pages in all files}:
$this = Class that extends mPDF class...
function mergePDFFiles(Array $filenames, $outFile)
{
if ($filenames) {
$filesTotal = sizeof($filenames);
$fileNumber = 1;
$this->SetImportUse(); // this line comment out if method doesnt exist
if (!file_exists($outFile)) {
$handle = fopen($outFile, 'w');
fclose($handle);
}
foreach ($filenames as $fileName) {
if (file_exists($fileName)) {
$pagesInFile = $this->SetSourceFile($fileName);
for ($i = 1; $i <= $pagesInFile; $i++) {
$tplId = $this->ImportPage($i); // in mPdf v8 should be 'importPage($i)'
$this->UseTemplate($tplId);
if (($fileNumber < $filesTotal) || ($i != $pagesInFile)) {
$this->WriteHTML(' ');
}
}
}
$fileNumber++;
}
$this->Output($outFile);
}
}