Page numbering trait

This commit is contained in:
David Bomba 2022-05-25 11:49:27 +10:00
parent 36f8dddc4d
commit bdb08bf93a
3 changed files with 347 additions and 299 deletions

View File

@ -0,0 +1,47 @@
<?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
{
public function pageNumbers($pdf_data_object)
{
// initiate PDF
$pdf = new PDF();
// set the source file
$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['width'], $templateSize['height']]);
$pdf->useTemplate($tplId);
}
return $pdf->Output();
}
}

View File

@ -14,7 +14,6 @@ namespace App\Utils\Traits\Pdf;
use App\Exceptions\InternalPDFFailure;
use Beganovich\Snappdf\Snappdf;
use setasign\Fpdi\PdfParser\StreamReader;
trait PdfMaker
{
@ -44,32 +43,6 @@ trait PdfMaker
->setHtml($html)
->generate();
// initiate PDF
$pdf = new PDF();
// set the source file
// $pageCount = $pdf->setSourceFile("file-1.pdf");
$pageCount = $pdf->setSourceFile(StreamReader::createByString($generated));
$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['width'], $templateSize['height']]);
// $pdf->AddPage();
//use the template of the imporated page
$pdf->useTemplate($tplId);
}
$generated = $pdf->Output();
if($generated)
return $generated;

572
composer.lock generated

File diff suppressed because it is too large Load Diff