Install TCPDF

I would like to get some advice from you to install TCPDF "Open Source PHP class for generating PDF documents". This library has not been installed with composer neither has an autoloader and has many classes in many directories. I was trying to installed it by move some classes to my phalcon library some has already running but the core of the library is not running.

https://github.com/tecnickcom/TCPDF

https://github.com/tecnickcom/tc-lib-pdf

Have you installed it using these sources? You only have to require the autoload file



38.3k

Hi,

using https://github.com/tecnickcom/TCPDF, I've put all the files and directories in the app/library folder. Tcpdf lib is loaded using the registerDir() function of phalcon loader. I've never managed to get it to work by placing all the stuff in a subdirectory of libraryDir

Pro: it works as expected.

Cons: it's a mess in your libraryDir.

HAPPY NEW YEAR EVERYONE !!!

Have you tried to use composer and require tool by it's repo name: tecnickcom/tcpdf?

I'm guessing you want to have the TCPDF available in your Dependency Injector, which is configured in your bootstrap file.

Let's say you download all the files into a app/libraries/tcpdf directory.

In your bootstrap.php file, you can include this:

$DI->setShared('tcpdf',function(){
    require_once '/path/to/app/libraries/tcpdf/tcpdf.php';
    return new TCPDF();
});

I think requiring that main tcpdf.php file will include the other files as necessary. You can then access the library through your Dependency Injector.

We install using Composer then have this code in our index.php. I've cut the relevant TCPDF code and included it here:

try { $app_directories = (object) array( "controllersDir" => "../app/controllers/", "modelsDir" => "../app/models/", "viewsDir" => "../app/views/", "vendorDir" => "../vendor" );

// include the composer autoload file.
include $app_directories->vendorDir . '/autoload.php';

//Create a DI
$di = new Phalcon\DI\FactoryDefault();

$di->setShared('db_creds', function() {
    return new \Phalcon\Config(yaml_parse_file('../app/config/database.yaml'));
});

$loader = new \Phalcon\Loader();

$loader->registerDirs(array(
    $app_directories->controllersDir,
    $app_directories->modelsDir
));

$loader->register();

$loader->registerClasses(array(
    'TCPDF' => $app_directories->vendorDir . 'tecnickcom/tcpdf/TCPDF.php',
    'TCPDFBarcode' => $app_directories->vendorDir . 'tecnickcom/tcpdf/tcpdf_barcodes_1d.php'
));
:
:
:

Thank you. Finally I installed mpdf with composer and it is working fine.

https://github.com/tecnickcom/TCPDF

https://github.com/tecnickcom/tc-lib-pdf

Have you installed it using these sources? You only have to require the autoload file