1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-22 09:21:34 +02:00
invoiceninja/app/Utils/Traits/Pdf/PageNumbering.php

55 lines
1.4 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)
{
2022-05-25 14:00:17 +02:00
2022-05-26 03:13:46 +02:00
if(!$company->settings->page_numbering)
return $pdf_data_object;
2022-05-25 14:00:17 +02:00
2022-05-25 08:34:43 +02:00
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);
}
2022-05-25 14:00:17 +02:00
return $pdf->Output('S');
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
}
}
}