1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-21 08:51:34 +02:00
invoiceninja/app/Services/PdfMaker/PdfMerge.php

41 lines
970 B
PHP
Raw Normal View History

2022-10-30 01:28:59 +02:00
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
2023-01-28 23:21:40 +01:00
* @copyright Copyright (c) 2023. 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;
use \setasign\Fpdi\Fpdi;
2023-02-16 02:36:09 +01:00
use Illuminate\Support\Facades\Storage;
2022-10-30 21:37:52 +01:00
use setasign\Fpdi\PdfParser\StreamReader;
2022-10-30 01:28:59 +02:00
class PdfMerge
{
2023-02-16 02:36:09 +01:00
public function __construct(private array $file_paths)
{
}
2022-10-30 01:28:59 +02:00
public function run()
{
$pdf = new FPDI();
foreach ($this->file_paths as $file) {
2022-10-30 21:37:52 +01:00
$pageCount = $pdf->setSourceFile(StreamReader::createByString(Storage::get($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');
}
}