Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

tebowner's avatar

tcpdf install

I am new to start off....

I used composer to install \tecnick.com\tcpdf

the docs say to use this example. Of course its not working as it need to know TCPDF somehow and this is where I am failing Laravel to understand. In PHP i can just require the page but now this is installed in \vendor and i am not sure how to move forward

$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);

        $pdf->SetCreator(PDF_CREATOR);
        $pdf->SetAuthor('Nicola Asuni');
        $pdf->SetTitle('TCPDF Example 001');
        
0 likes
4 replies
bobbybouwmann's avatar

Well if you want to use a package you need the proper namespace. I don't know what the directory structure is but it's most likely something like this

vender/technick/tcpdf

Now most packages have the same namespace as their directory structure so you can do this on the top of your file use Technick/Tcpdf`/TCPDF;

What you can do to be sure is dive in the code of in the vendor directory and look for the class TCPDF. This file has a namespace at the top like every other file. Copy the namespace at the top and add /TCPDF to it and you should be fine. So if the file looks like this

<?php namespace Technick/PDF;

class TCPDF ...

Then you use statement looks like this

use Technick/PDF/TCPDF:

Now you can access the TCPDF class with no problems ;)

tebowner's avatar

@bobbybouwmann I dont see namespace on this file at all.

<?php
//============================================================+
// File name   : tcpdf.php
// Version     : 6.2.8
// Begin       : 2002-08-03
// Last Update : 2015-04-29
// Author      : Nicola Asuni - Tecnick.com LTD - www.tecnick.com - info@tecnick.com
// License     : GNU-LGPL v3 (http://www.gnu.org/copyleft/lesser.html)
// -------------------------------------------------------------------
// Copyright (C) 2002-2015 Nicola Asuni - Tecnick.com LTD
//
// TCPDF configuration
require_once(dirname(__FILE__).'/tcpdf_autoconfig.php');
// TCPDF static font methods and data
require_once(dirname(__FILE__).'/include/tcpdf_font_data.php');
// TCPDF static font methods and data
require_once(dirname(__FILE__).'/include/tcpdf_fonts.php');
// TCPDF static color methods and data
require_once(dirname(__FILE__).'/include/tcpdf_colors.php');
// TCPDF static image methods and data
require_once(dirname(__FILE__).'/include/tcpdf_images.php');
// TCPDF static methods and data
require_once(dirname(__FILE__).'/include/tcpdf_static.php');

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

/**
 * @class TCPDF
 * PHP class for generating PDF documents without requiring external extensions.
 * TCPDF project (http://www.tcpdf.org) has been originally derived in 2002 from the Public Domain FPDF class by Olivier Plathey (http://www.fpdf.org), but now is almost entirely rewritten.<br>
 * @package com.tecnick.tcpdf
 * @brief PHP class for generating PDF documents without requiring external extensions.
 * @version 6.2.8
 * @author Nicola Asuni - info@tecnick.com
 */
class TCPDF {

    // Protected properties

    /**
     * Current page number.
     * @protected
     */
    protected $page;

    /**
     * Current object number.

bobbybouwmann's avatar

Then using newTCPDF()` should be fine... Did you check the documentation or asked them how to do it?

tebowner's avatar

i installed a laravel based tcpdf wrapper someone had...this worked well as it had a provider. thank you

Please or to participate in this conversation.