From bfa5e045500f0628258678936c57be788c9108d5 Mon Sep 17 00:00:00 2001 From: imnavajas Date: Thu, 2 Nov 2023 22:59:29 +0100 Subject: [PATCH] Integrada libreria dompdf y ejemplo hola mundo --- ci4/.env | 4 +- ci4/app/Config/Autoload.php | 1 + ci4/app/Config/Routes.php | 4 + ci4/app/Controllers/Pdf/PdfController.php | 24 +++++ ci4/app/Views/pdf_view.php | 115 ++++++++++++++++++++++ ci4/composer.json | 3 +- 6 files changed, 148 insertions(+), 3 deletions(-) create mode 100644 ci4/app/Controllers/Pdf/PdfController.php create mode 100644 ci4/app/Views/pdf_view.php diff --git a/ci4/.env b/ci4/.env index cfd0651b..40f48c5f 100644 --- a/ci4/.env +++ b/ci4/.env @@ -22,8 +22,8 @@ CI_ENVIRONMENT = development # APP #-------------------------------------------------------------------- -app.baseURL = 'https://sk-jjo.imnavajas.es' -#app.baseURL = 'https://sk-imn.imnavajas.es' +#app.baseURL = 'https://sk-jjo.imnavajas.es' +app.baseURL = 'https://sk-imn.imnavajas.es' # app.baseURL = "http://safekat.test/" # app.forceGlobalSecureRequests = false diff --git a/ci4/app/Config/Autoload.php b/ci4/app/Config/Autoload.php index ee27e3b2..5f149426 100644 --- a/ci4/app/Config/Autoload.php +++ b/ci4/app/Config/Autoload.php @@ -43,6 +43,7 @@ class Autoload extends AutoloadConfig public $psr4 = [ APP_NAMESPACE => APPPATH, // For custom app namespace 'Config' => APPPATH . 'Config', + 'Dompdf' => APPPATH . 'ThirdParty/dompdf/src', ]; /** diff --git a/ci4/app/Config/Routes.php b/ci4/app/Config/Routes.php index 9ec4772e..84f7f385 100644 --- a/ci4/app/Config/Routes.php +++ b/ci4/app/Config/Routes.php @@ -50,6 +50,10 @@ $routes->delete('api/user/(:segment)', 'Api::user/delete/$1'); * Route Definitions * -------------------------------------------------------------------- */ +$routes->group('pdfcontroller', ['namespace' => 'App\Controllers\Pdf'], function ($routes) { + $routes->get('', 'PdfController::index', ['as' => 'pdfList']); + $routes->match(['get', 'post'], 'htmltopdf', 'PdfController::htmlToPDF', ['as' => 'toPdf']); +}); $routes->group('tarifaacabado', ['namespace' => 'App\Controllers\Tarifas'], function ($routes) { $routes->get('', 'Tarifaacabado::index', ['as' => 'tarifaAcabadoList']); diff --git a/ci4/app/Controllers/Pdf/PdfController.php b/ci4/app/Controllers/Pdf/PdfController.php new file mode 100644 index 00000000..6bcfc44d --- /dev/null +++ b/ci4/app/Controllers/Pdf/PdfController.php @@ -0,0 +1,24 @@ + true]); + $dompdf->loadHtml(view('pdf_view')); + $dompdf->setPaper('A4', 'portrait'); + $dompdf->render(); + $dompdf->stream(); + } +} \ No newline at end of file diff --git a/ci4/app/Views/pdf_view.php b/ci4/app/Views/pdf_view.php new file mode 100644 index 00000000..69fc8975 --- /dev/null +++ b/ci4/app/Views/pdf_view.php @@ -0,0 +1,115 @@ + + + + + + Codeigniter 4 PDF Example - positronx.io + + + + +
+

Generate PDF in Codeigniter from View

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameProfileCityDateCTC
Airi SatouAccountantTokyo332008/11/28$162,700
Angelica RamosChief Executive Officer (CEO)London472009/10/09$1,200,000
Ashton CoxJunior Technical AuthorSan Francisco662009/01/12$86,000
Bradley GreerSoftware EngineerLondon412012/10/13$132,000
Brenden WagnerSoftware EngineerSan Francisco282011/06/07$206,850
Brielle WilliamsonIntegration SpecialistNew York612012/12/02$372,000
Bruno NashSoftware EngineerLondon382011/05/03$163,500
Caesar VancePre-Sales SupportNew York212011/12/12$106,450
Cara StevensSales AssistantNew York462011/12/06$145,600
Cedric KellySenior Javascript DeveloperEdinburgh222012/03/29$433,060
+
+ + diff --git a/ci4/composer.json b/ci4/composer.json index 687cdb91..c2b4eef4 100644 --- a/ci4/composer.json +++ b/ci4/composer.json @@ -11,7 +11,8 @@ "google/apiclient": "^2.11.0", "firebase/php-jwt": "^5.4", "aws/aws-sdk-php": "^3.206", - "spatie/db-dumper": "^2.21" + "spatie/db-dumper": "^2.21", + "dompdf/dompdf": "^2.0" }, "require-dev": { "fakerphp/faker": "^1.9",