CodeIgniter Forums
Use of FPDF library 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: Use of FPDF library in CI4 (/showthread.php?tid=83605)



Use of FPDF library in CI4 - foxbille - 10-10-2022

Hello guys,
As I need fpdf in my project, I have installed it thru seatsign/fpdf found in packagist.org, using :

composer require setasign/fpdf:^1.8

It is now present in the vendor\setasign\fpdf directory of my app

To get it in my project, I have put a file MyFpdfClass.php in \APP\Libraries containing :
<?php
namespace App\Libraries;
use \setasign\fpdf\fpdf;
[...]
class MyFpdfClass extends Fpdf
{

but the call in controller $t = new MyFpdfClass() send an error :

Class "setasign\fpdf\fpdf" not found
APPPATH/Libraries/MyFpdfClass.php at line 13

How can I set the "use" so that the library is found ?
Is it a problem with autoloader not correctly set ?

Thanks for your help
Eric


RE: Use of FPDF library in CI4 - ozornick - 10-10-2022

Use modern IDE for development. Have autoimport namespaces

PHP Code:
<?php

namespace App\Libraries;

use 
FPDF;

class 
MyFpdfClass extends FPDF
{





RE: Use of FPDF library in CI4 - captain-sensible - 10-10-2022

if you integrated seatsign/fpdf using composer, then to use the classes of that package in a controller it would be in the form of :

Code:
use  fullNamespaceName\classname   //Youwant to use

To get the namespace open up one of the classes with a text editor.
For instance i used composer to integrate PHPMailer into CI4

opening up one of the classes i saw they used the namespace
Code:
PHPMialer\PHPMailer

I noticed there were few classes , of which one class of PHPMailer might need to use another, so in my controller, where I will instantiate i wrote
Code:
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\OAuth;
use PHPMailer\PHPMailer\Exception;
use PHPMailer\PHPMailer\SMTP;

then in the same controller to instantiate it was just :

Code:
$mail = new PHPMailer(true);

Now if you used composer to install , CI should know exactly where classes are , via autoload. So you should have to shift things about or mess with autoload class. Previously i manually put in PHPMailer at root level ; in that case I did have to make use of autoload.php and the section

Code:
public $psr4 = [
        APP_NAMESPACE => APPPATH, // For custom app namespace
        
        
        'Config'      => APPPATH . 'Config',
        'PHPMailer\\PHPMailer'=> ROOTPATH.'PHPMailer/src',
        
        
    ];

The point as i understand it is that with composer , if the classes integrated in vendor , DO HAVE a namespace in the classes, then you shouldn't have to do anything excpet make use of "use"


RE: Use of FPDF library in CI4 - foxbille - 10-10-2022

This helps ! Thank you so much !!


RE: Use of FPDF library in CI4 - abatrans - 10-11-2022

I have found that mPdf is much easier to configure and to use. Install via composer.

Especially where you already have the output in html/css and just need to output as a pdf.

Give it a look. The docs can be found here https://mpdf.github.io/


RE: Use of FPDF library in CI4 - captain-sensible - 10-11-2022

i got this one working on one of my old sites : https://packagist.org/packages/tecnickcom/tcpdf


RE: Use of FPDF library in CI4 - DunogRamers - 11-04-2022

I want use fpdf in my project CI4.. how i can do this step by step? How include it as thirdparty?!

<?php namespace App\Controllers\Purchase;

namespace App\ThirdParty\fpdf;

use CodeIgniter\Controller;

use FPDF;
?>
and how build the controller to call fpdf methods?!

$pdf = new PDF();
$pdf->AddPage();
thanks