Files
Antonio Lopes dos Santos afec302c3e
All checks were successful
build-api-image / build (push) Successful in 51s
init commit
2026-08-04 16:52:02 -03:00

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');
}
}