This is not about adding by composer. This is about downloading and then using it. For Example: I download TCPDF Library and follows these steps it should be installed and usable but it doesn't works as explained.

When we need use this line?

require_once DIR . '/../../../../../lib/folder/folder/ntlmstream.php';

What is the Role of autoload?



2 Answers 2


This is the way I figured for TCPDF Library:

  1. Download TCPDF from https://github.com/tecnickcom/tcpdf

  2. Change the name of the file root directory after extraction to TCPDF

  3. Inside this directory, there is a tcpdf.php file, change the name to TCPDF

  4. Open the file and change the class name from tcpdf to TCPDF_TCPDF

  5. Copy the files into your Magento “lib/internal” folder in the root Magento installation directory.

=>So it should look like this: lib/internal/TCPDF

Now, write below statement in the class where you want to make tcpdf object:


And use this class as:

$tcpdf = new \TCPDF_TCPDF();

Example Code is:


namespace Vendor\Module\Controller\Adminhtml\Generatepdf;

use Magento\Backend\App\Action\Context;
use Magento\Framework\App\Filesystem\DirectoryList;


class CreatePdf extends \Magento\Backend\App\Action  {

protected $_dir;
protected $customerName;
protected $order;
public function __construct(
Context $context,
Order $order,
DirectoryList $dir

$this->order = $order;
$this->_dir = $dir;


public function execute() {





// set default monospaced font


// set margins




// set auto page breaks

$tcpdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);

// set image scale factor


// set some language-dependent strings (optional)

if (@file_exists(dirname(__FILE__) . '/lang/eng.php')) {

    require_once(dirname(__FILE__) . '/lang/eng.php');



// ---------------------------------------------------------

// set default font subsetting mode


//your htmls here


// set some language dependent data:

$lg = Array();

$lg['a_meta_charset'] = 'UTF-8';


// set font

//dejavusans & freesans For Indian Rupees symbol

$tcpdf->SetFont('freesans', '', 12);

// remove default header/footer




$tcpdf->writeHTML($html, true, false, true, false, '');


//$tcpdf->Output('report_per_route.pdf', 'I');

$baseurl = $this->getDirPath();
$filename = $baseurl .'/export/'. 'Sample_pdf'. time().'.pdf';
$tcpdf->Output($filename, 'I');


Happy coding :)

  • Thanks for the solution, I havent tried your way till now, but I have a question, Is there any way to bind it in custom module under m2root/app/code/name_space/ ? Commented Mar 6, 2019 at 11:53
  • I tried by binding it in custom module but TCPDF lib was not responding. But I think their must be a way like that.. Above is perfectly working way. You try if it works then share the way here as well.
    – Ajwad Syed
    Commented Mar 8, 2019 at 14:04
  • What if the class you are trying to run is withing a subfolder? An example is Phpseclib2. Full path is "/lib/internal/phpseclib2/Net/SFTP.php". Commented Jun 13, 2019 at 18:23

I wanna to add some information for Ajwad Syed answer. You can add this

require_once(BP . '/lib/internal/TCPDF/TCPDF.php');

to registration.php of your module and it will be work and it works correctly because for nginx require_once('lib/internal/TCPDF/TCPDF.php'); dont work, because pub the main dir of index.php and it search lib/internal/TCPDF/TCPDF.php in pub dir. Maybe for somebody will be usefull

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.