You are copying code you don't understand and you get an error. And these are the basics of PHP.
PHP Code:
use App\ThirdParty\TCPDF\Tcpdf;
This line is trying to import the class and
1. The class file must be reachable through the path
App/ThirdParty/TCPDF/Tcpdf.php
2. The class must be in the specified namespace (App\ThirdParty\TCPDF)
.
If you haven't guessed yet, then the shared library will not have the
App\ThirdParty\TCPDF namespace.
That's why you get your error.
There are 2 simple solutions.
CodeIgniter way
1. Unpack the library from github to ThirdParty/TCPDF
2. Change config App/Config/Autoload.
Add the line to the $classmap property
PHP Code:
public $classmap = [
'TCPDF' => APPPATH . '/ThirdParty/TCPDF/tcpdf.php',
];
3. Import the library into your controller.
PHP Code:
<?php
namespace Your\Controller\Namespace
use TCPDF;
Now you can create an instance of the class.
The easy way
1.Install the library with composer
Code:
composer require tecnickcom/tcpdf
2. Import the library into your controller.
PHP Code:
<?php
namespace Your\Controller\Namespace
use TCPDF;