1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-11 13:42:49 +01:00
invoiceninja/app/Utils/Traits/Pdf/PageNumbering.php

53 lines
1.3 KiB
PHP
Raw Normal View History

2022-05-25 03:49:27 +02:00
<?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
{
2022-05-25 08:34:43 +02:00
private function pageNumbering($pdf_data_object, $company)
{
try
{
$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-05-25 08:34:43 +02:00
for ($i=1; $i <= $pageCount; $i++) {
//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-05-25 08:34:43 +02:00
//create a page
$templateSize = $pdf->getTemplateSize($tplId);
$pdf->AddPage($templateSize['orientation'], [$templateSize['width'], $templateSize['height']]);
$pdf->useTemplate($tplId);
}
ob_end_flush();
return $pdf->Output();
2022-05-25 03:49:27 +02:00
2022-05-25 08:34:43 +02:00
}
catch(\Exception $e) {
nlog($e->getMessage());
2022-05-25 03:49:27 +02:00
2022-05-25 08:34:43 +02:00
}
}
}