2022-10-30 01:28:59 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Invoice Ninja (https://invoiceninja.com).
|
|
|
|
*
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
*
|
2024-04-12 06:15:41 +02:00
|
|
|
* @copyright Copyright (c) 2024. Invoice Ninja LLC (https://invoiceninja.com)
|
2022-10-30 01:28:59 +02:00
|
|
|
*
|
|
|
|
* @license https://www.elastic.co/licensing/elastic-license
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace App\Services\PdfMaker;
|
|
|
|
|
2024-01-14 05:05:00 +01:00
|
|
|
use setasign\Fpdi\Fpdi;
|
2022-10-30 21:37:52 +01:00
|
|
|
use setasign\Fpdi\PdfParser\StreamReader;
|
2022-10-30 01:28:59 +02:00
|
|
|
|
|
|
|
class PdfMerge
|
|
|
|
{
|
2023-09-05 02:49:16 +02:00
|
|
|
/**
|
|
|
|
* __construct
|
|
|
|
*
|
|
|
|
* @param array $files
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function __construct(private array $files)
|
2023-02-16 02:36:09 +01:00
|
|
|
{
|
|
|
|
}
|
2022-10-30 01:28:59 +02:00
|
|
|
|
|
|
|
public function run()
|
|
|
|
{
|
|
|
|
$pdf = new FPDI();
|
|
|
|
|
2023-09-05 02:49:16 +02:00
|
|
|
foreach ($this->files as $file) {
|
|
|
|
$pageCount = $pdf->setSourceFile(StreamReader::createByString($file));
|
2022-10-30 01:28:59 +02:00
|
|
|
for ($i = 0; $i < $pageCount; $i++) {
|
|
|
|
$tpl = $pdf->importPage($i + 1, '/MediaBox');
|
|
|
|
$pdf->addPage();
|
|
|
|
$pdf->useTemplate($tpl);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $pdf->Output('S');
|
|
|
|
}
|
|
|
|
}
|