1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-15 07:33:04 +01:00
invoiceninja/app/Utils/Traits/Pdf/PageNumbering.php
2024-04-12 14:15:41 +10:00

51 lines
1.4 KiB
PHP

<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2024. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://www.elastic.co/licensing/elastic-license
*/
namespace App\Utils\Traits\Pdf;
use setasign\Fpdi\PdfParser\StreamReader;
trait PageNumbering
{
private function pageNumbering($pdf_data_object, $company)
{
if (! property_exists($company->settings, 'page_numbering') || ! $company->settings->page_numbering) {
return $pdf_data_object;
}
try {
$pdf = new PDF();
$pdf->setAlignment($company->getSetting('page_numbering_alignment'));
$pageCount = $pdf->setSourceFile(StreamReader::createByString($pdf_data_object));
$pdf->AliasNbPages();
for ($i = 1; $i <= $pageCount; $i++) {
//import a page then get the id and will be used in the template
$tplId = $pdf->importPage($i);
//create a page
$templateSize = $pdf->getTemplateSize($tplId);
$pdf->AddPage($templateSize['orientation'], [$templateSize['width'], $templateSize['height']]);
$pdf->useTemplate($tplId);
}
return $pdf->Output('S');
} catch (\Exception $e) {
nlog($e->getMessage());
}
}
}