1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-13 14:42:42 +01:00
invoiceninja/app/Utils/Traits/Pdf/PageNumbering.php
2022-05-25 16:34:43 +10:00

53 lines
1.3 KiB
PHP

<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2022. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://www.elastic.co/licensing/elastic-license
*/
namespace App\Utils\Traits\Pdf;
use App\Utils\Traits\Pdf\PDF;
use setasign\Fpdi\PdfParser\StreamReader;
trait PageNumbering
{
private function pageNumbering($pdf_data_object, $company)
{
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);
}
ob_end_flush();
return $pdf->Output();
}
catch(\Exception $e) {
nlog($e->getMessage());
}
}
}