CodeIgniter Forums
how to call class FPDF in CI4 - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=11)
+--- Thread: how to call class FPDF in CI4 (/showthread.php?tid=80480)



how to call class FPDF in CI4 - ghete - 11-06-2021

Hi guys .. please give some suggestion for my problem ..
i want to make some report using FPDF with CI4
 ==== it s my controller =====
<?php namespace App\Controllers;

use App\ThirdParty\FPDF;

public function laporan(){
$pdf=new UMUM('P','mm','Legal');

$pdf->SetMargins(5,7,5);
$pdf->SetAutoPageBreak(true,20);
$pdf->AliasNbPages('{pages}');
$pdf->AddPage();
$this->response->setHeader('Content-Type','application/pdf');


the problem is how to call class UMUM in CI 4  ... i tried it in CI 3 and it work but it doesn't work in CI 4


RE: how to call class FPDF in CI4 - captain-sensible - 11-07-2021

is this about PDf ? i got results with Spipu\Html2Pdf\Html2Pdf; for producing pdf


RE: how to call class FPDF in CI4 - ghete - 11-07-2021

yes ..its about PDF &  i'm using FPDF to make report in CI 4..
theres's some problem when i'm make a report FPDF.. i've made UMUM class (header, footer, pages) but i dont know how to call those class in CI 4 ??


RE: how to call class FPDF in CI4 - krunkeriogm - 11-11-2021

When we install CodeIgniter 4, we have env file at root. To use the environment variables means using variables at global scope we need to do env to .env
Open project in terminal
$ cp env .env
Above command will create a copy of env file to .env file. Now we are ready to use environment variables.
CodeIgniter starts up in production mode by default. Let’s do it in development mode. So that while working if we get any error then error will show up.
# CI_ENVIRONMENT = production
// Do it to
CI_ENVIRONMENT = development
Now application is in development mode.


RE: how to call class FPDF in CI4 - nurmyrat - 12-27-2021

(11-06-2021, 03:58 PM)ghete Wrote: Hi guys .. please give some suggestion for my problem ..
i want to make some report using FPDF with CI4
 ==== it s my controller =====
<?php namespace App\Controllers;

use App\ThirdParty\FPDF;

public function laporan(){
$pdf=new UMUM('P','mm','Legal');

$pdf->SetMargins(5,7,5);
$pdf->SetAutoPageBreak(true,20);
$pdf->AliasNbPages('{pages}');
$pdf->AddPage();
$this->response->setHeader('Content-Type','application/pdf');


the problem is how to call class UMUM in CI 4  ... i tried it in CI 3 and it work but it doesn't work in CI 4

CI3 uses autoload by default, In CI4 you should show where use App\ThirdParty\FPDF; is located by name.
I solve this problem 
1) by going into App directory, 
2) if there none Create ThirdParty directory. 
3) then entered compose init, 
4) after some initialization entered by you enter  "composer require twig/twig" (as an example) 
once the composer sets up all the folders for you, 
5) download the FPDF zip file unzip to into vendor directory by the name fpdf
6) add the following  to the app\thirdparty\vendor\composer\autoload_psr4.php file
return array(
            ....
            ....
            'FPDF\\' => array($vendorDir . '/fpdf'),
);

or you can add the same thing into App\Config\Autoload.php file.. make sure you show the link of the file correctly.