mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Page numbering trait
This commit is contained in:
parent
36f8dddc4d
commit
bdb08bf93a
47
app/Utils/Traits/Pdf/PageNumbering.php
Normal file
47
app/Utils/Traits/Pdf/PageNumbering.php
Normal 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();
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -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
572
composer.lock
generated
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user