diff --git a/app/Utils/Traits/Pdf/PDF.php b/app/Utils/Traits/Pdf/PDF.php new file mode 100644 index 000000000..9e1e505d9 --- /dev/null +++ b/app/Utils/Traits/Pdf/PDF.php @@ -0,0 +1,23 @@ +SetY(-7); + // $this->SetX(-50); + + $this->SetXY(0, -5); + + // Arial italic 8 + $this->SetFont('Arial','I',8); + // Page number + $this->Cell(0,5, ctrans('texts.page').' '.$this->PageNo().'/{nb}',0,0,'C'); + } +} \ No newline at end of file diff --git a/app/Utils/Traits/Pdf/PdfMaker.php b/app/Utils/Traits/Pdf/PdfMaker.php index 7c33990b4..f21bba9fd 100644 --- a/app/Utils/Traits/Pdf/PdfMaker.php +++ b/app/Utils/Traits/Pdf/PdfMaker.php @@ -14,6 +14,7 @@ namespace App\Utils\Traits\Pdf; use App\Exceptions\InternalPDFFailure; use Beganovich\Snappdf\Snappdf; +use setasign\Fpdi\PdfParser\StreamReader; trait PdfMaker { @@ -43,6 +44,32 @@ 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; diff --git a/composer.json b/composer.json index 936fc0c37..dd97adf32 100644 --- a/composer.json +++ b/composer.json @@ -74,6 +74,8 @@ "predis/predis": "^1.1", "razorpay/razorpay": "2.*", "sentry/sentry-laravel": "^2", + "setasign/fpdf": "^1.8", + "setasign/fpdi": "^2.3", "square/square": "13.0.0.20210721", "stripe/stripe-php": "^7.50", "symfony/http-client": "^5.2", @@ -148,4 +150,4 @@ }, "minimum-stability": "dev", "prefer-stable": true -} \ No newline at end of file +} diff --git a/composer.lock b/composer.lock index ee703998a..897642caa 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "9bc9b45c0c0864b0f16869ba0870fde5", + "content-hash": "7b3f79c9cba4d88565a17f269a2184a2", "packages": [ { "name": "afosto/yaac", @@ -7831,6 +7831,124 @@ ], "time": "2022-04-05T10:05:19+00:00" }, + { + "name": "setasign/fpdf", + "version": "1.8.4", + "source": { + "type": "git", + "url": "https://github.com/Setasign/FPDF.git", + "reference": "b0ddd9c5b98ced8230ef38534f6f3c17308a7974" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Setasign/FPDF/zipball/b0ddd9c5b98ced8230ef38534f6f3c17308a7974", + "reference": "b0ddd9c5b98ced8230ef38534f6f3c17308a7974", + "shasum": "" + }, + "require": { + "ext-gd": "*", + "ext-zlib": "*" + }, + "type": "library", + "autoload": { + "classmap": [ + "fpdf.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Olivier Plathey", + "email": "oliver@fpdf.org", + "homepage": "http://fpdf.org/" + } + ], + "description": "FPDF is a PHP class which allows to generate PDF files with pure PHP. F from FPDF stands for Free: you may use it for any kind of usage and modify it to suit your needs.", + "homepage": "http://www.fpdf.org", + "keywords": [ + "fpdf", + "pdf" + ], + "support": { + "source": "https://github.com/Setasign/FPDF/tree/1.8.4" + }, + "time": "2021-08-30T07:50:06+00:00" + }, + { + "name": "setasign/fpdi", + "version": "v2.3.6", + "source": { + "type": "git", + "url": "https://github.com/Setasign/FPDI.git", + "reference": "6231e315f73e4f62d72b73f3d6d78ff0eed93c31" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Setasign/FPDI/zipball/6231e315f73e4f62d72b73f3d6d78ff0eed93c31", + "reference": "6231e315f73e4f62d72b73f3d6d78ff0eed93c31", + "shasum": "" + }, + "require": { + "ext-zlib": "*", + "php": "^5.6 || ^7.0 || ^8.0" + }, + "conflict": { + "setasign/tfpdf": "<1.31" + }, + "require-dev": { + "phpunit/phpunit": "~5.7", + "setasign/fpdf": "~1.8", + "setasign/tfpdf": "1.31", + "squizlabs/php_codesniffer": "^3.5", + "tecnickcom/tcpdf": "~6.2" + }, + "suggest": { + "setasign/fpdf": "FPDI will extend this class but as it is also possible to use TCPDF or tFPDF as an alternative. There's no fixed dependency configured." + }, + "type": "library", + "autoload": { + "psr-4": { + "setasign\\Fpdi\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Jan Slabon", + "email": "jan.slabon@setasign.com", + "homepage": "https://www.setasign.com" + }, + { + "name": "Maximilian Kresse", + "email": "maximilian.kresse@setasign.com", + "homepage": "https://www.setasign.com" + } + ], + "description": "FPDI is a collection of PHP classes facilitating developers to read pages from existing PDF documents and use them as templates in FPDF. Because it is also possible to use FPDI with TCPDF, there are no fixed dependencies defined. Please see suggestions for packages which evaluates the dependencies automatically.", + "homepage": "https://www.setasign.com/fpdi", + "keywords": [ + "fpdf", + "fpdi", + "pdf" + ], + "support": { + "issues": "https://github.com/Setasign/FPDI/issues", + "source": "https://github.com/Setasign/FPDI/tree/v2.3.6" + }, + "funding": [ + { + "url": "https://tidelift.com/funding/github/packagist/setasign/fpdi", + "type": "tidelift" + } + ], + "time": "2021-02-11T11:37:01+00:00" + }, { "name": "square/square", "version": "13.0.0.20210721",