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

52 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;
2022-05-25 03:49:27 +02:00
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)
{
if (! property_exists($company->settings, 'page_numbering') || ! $company->settings->page_numbering) {
2022-05-26 03:13:46 +02:00
return $pdf_data_object;
}
2022-05-25 14:00: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
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
//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
return $pdf->Output('S');
} catch (\Exception $e) {
2022-05-25 08:34:43 +02:00
nlog($e->getMessage());
}
2022-05-25 08:34:43 +02:00
}
}