How To Merge 2 PDF in MPDF Using PHP Laravel - Stack Overflow

PHOTO EMBED

Thu Dec 14 2023 11:42:09 GMT+0000 (Coordinated Universal Time)

Saved by @zaryabmalik #php

function mergePdf($pdfArr){
    $pdf = new Mpdf();
    foreach($pdfArr as $currentPdf){
      $pagecount = $pdf->SetSourceFile($currentPdf);
      for($i = 1; $i <= $pagecount; $i++){
        $pdf->AddPage();
        $tplId = $pdf->importPage($i);
        $pdf->useTemplate($tplId);
      }
    }
    //direct show on browser
    $pdf->Output();
    
    //spacefic location save file
    $outputpath = 'location/output.pdf';
    $pdf->Output($outputpath, 'F');
}
content_copyCOPY

https://stackoverflow.com/questions/69294670/how-to-merge-2-pdf-in-mpdf-using-php-laravel