Skip to content

Instantly share code, notes, and snippets.

@rafsuntaskin
Last active February 9, 2018 03:53
Show Gist options
  • Save rafsuntaskin/d23279b8eefa3cc5f76d948a0a6de80b to your computer and use it in GitHub Desktop.
Save rafsuntaskin/d23279b8eefa3cc5f76d948a0a6de80b to your computer and use it in GitHub Desktop.
mpdf Stich PDFS or Merge multiple pdfs
<?php
function custom_yith_merge_PDF_Slips(Array $filenames, $outFile) {
$mpdf = new mPDF();
if ($filenames) {
$filesTotal = sizeof($filenames);
$fileNumber = 1;
$mpdf->SetImportUse();
if (!file_exists($outFile)) {
$handle = fopen($outFile, 'w');
fclose($handle);
}
foreach ($filenames as $fileName) {
if (file_exists($fileName)) {
$pagesInFile = $mpdf->SetSourceFile($fileName);
//print_r($fileName); die;
for ($i = 1; $i <= $pagesInFile; $i++) {
$tplId = $mpdf->ImportPage($i);
$mpdf->UseTemplate($tplId);
if (($fileNumber < $filesTotal) || ($i != $pagesInFile)) {
$mpdf->WriteHTML('<pagebreak />');
}
}
}
$fileNumber++;
}
$mpdf->Output();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment