2022-05-25 03:49:27 +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-05-25 03:49:27 +02:00
|
|
|
*
|
|
|
|
* @license https://www.elastic.co/licensing/elastic-license
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace App\Utils\Traits\Pdf;
|
2022-06-21 11:57:17 +02:00
|
|
|
|
2022-05-25 03:49:27 +02:00
|
|
|
use setasign\Fpdi\PdfParser\StreamReader;
|
|
|
|
|
|
|
|
trait PageNumbering
|
|
|
|
{
|
2022-05-25 08:34:43 +02:00
|
|
|
private function pageNumbering($pdf_data_object, $company)
|
|
|
|
{
|
2022-06-21 11:57:17 +02:00
|
|
|
if (! property_exists($company->settings, 'page_numbering') || ! $company->settings->page_numbering) {
|
2022-05-26 03:13:46 +02:00
|
|
|
return $pdf_data_object;
|
2022-06-21 11:57:17 +02:00
|
|
|
}
|
2022-05-25 14:00:17 +02:00
|
|
|
|
2022-06-21 11:57:17 +02:00
|
|
|
try {
|
2022-05-25 08:34:43 +02:00
|
|
|
$pdf = new PDF();
|
2022-05-25 03:49:27 +02:00
|
|
|
|
2022-05-25 08:34:43 +02:00
|
|
|
$pdf->setAlignment($company->getSetting('page_numbering_alignment'));
|
2022-05-25 03:49:27 +02:00
|
|
|
|
2022-05-25 08:34:43 +02:00
|
|
|
$pageCount = $pdf->setSourceFile(StreamReader::createByString($pdf_data_object));
|
2022-05-25 03:49:27 +02:00
|
|
|
|
2022-05-25 08:34:43 +02:00
|
|
|
$pdf->AliasNbPages();
|
2022-05-25 03:49:27 +02:00
|
|
|
|
2022-06-21 11:57:17 +02:00
|
|
|
for ($i = 1; $i <= $pageCount; $i++) {
|
2022-05-25 08:34:43 +02:00
|
|
|
//import a page then get the id and will be used in the template
|
|
|
|
$tplId = $pdf->importPage($i);
|
2022-05-25 03:49:27 +02:00
|
|
|
|
2022-06-21 11:57:17 +02:00
|
|
|
//create a page
|
2022-05-25 08:34:43 +02:00
|
|
|
$templateSize = $pdf->getTemplateSize($tplId);
|
|
|
|
|
|
|
|
$pdf->AddPage($templateSize['orientation'], [$templateSize['width'], $templateSize['height']]);
|
|
|
|
|
|
|
|
$pdf->useTemplate($tplId);
|
|
|
|
}
|
2022-05-25 03:49:27 +02:00
|
|
|
|
2022-06-21 11:57:17 +02:00
|
|
|
return $pdf->Output('S');
|
|
|
|
} catch (\Exception $e) {
|
2022-05-25 08:34:43 +02:00
|
|
|
nlog($e->getMessage());
|
2022-06-21 11:57:17 +02:00
|
|
|
}
|
2022-05-25 08:34:43 +02:00
|
|
|
}
|
|
|
|
}
|