34 lines
1.0 KiB
PHP
34 lines
1.0 KiB
PHP
<?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');
|
|
}
|
|
}
|