This commit is contained in:
33
api/app/Utils/Exports/PhpMerge.php
Normal file
33
api/app/Utils/Exports/PhpMerge.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Utils\Exports;
|
||||
|
||||
use setasign\Fpdi\Fpdi;
|
||||
use setasign\Fpdi\PdfParser\StreamReader;
|
||||
|
||||
class PhpMerge
|
||||
{
|
||||
public static function mergePdfDocuments($documentTitle, $pdfContents)
|
||||
{
|
||||
$pdf = new Fpdi();
|
||||
|
||||
foreach ($pdfContents as $pdfContent) {
|
||||
|
||||
$streamReader = StreamReader::createByString($pdfContent['data']);
|
||||
$pageCount = $pdf->setSourceFile($streamReader);
|
||||
|
||||
for ($pageNo = 1; $pageNo <= $pageCount; $pageNo++) {
|
||||
$templateId = $pdf->importPage($pageNo);
|
||||
$pdf->AddPage($pdfContent['orientation'], 'A4');
|
||||
$pdf->useTemplate($templateId);
|
||||
}
|
||||
}
|
||||
|
||||
return response($pdf->Output($documentTitle . '.pdf', 'S'))
|
||||
->header('Content-Type', 'application/pdf')
|
||||
->header('Content-Disposition', 'inline; filename="' . $documentTitle . '.pdf"')
|
||||
->header('Cache-Control', 'no-cache, no-store, must-revalidate')
|
||||
->header('Pragma', 'no-cache')
|
||||
->header('Expires', '0');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user