Last active
February 9, 2018 03:53
-
-
Save rafsuntaskin/d23279b8eefa3cc5f76d948a0a6de80b to your computer and use it in GitHub Desktop.
mpdf Stich PDFS or Merge multiple pdfs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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