Replies: 3   Views: 1882
Cannot redeclare class tcpdf
Topic closed:
Please note this is an old forum thread. Information in this post may be out-to-date and/or erroneous.
Every phpdocx version includes new features and improvements. Previously unsupported features may have been added to newer releases, or past issues may have been corrected.
We encourage you to download the current phpdocx version and check the Documentation available.

Posted by therasim  · 28-02-2017 - 12:01

I'm using PHPDocX and Spipu's HTML2PDF library ( together. With PHPDocX I'm not generating any PDF documents; however, I'm getting this error when I try to generate my Word document:

Fatal error: Cannot redeclare class TCPDF in /files/www/html/phpdocx/lib/pdf/tcpdf/tcpdf.php on line 152

Is there a way to bypass this error? Or is there a line I can modify to check if the library was already called?

Thanks in advance for any hints

Posted by therasim  · 28-02-2017 - 12:16

I commented the line 

spl_autoload_register(array('Phpdocx\AutoLoader', 'autoloadPdf'));

in the and that seemed to work for me; I just wonder if that's the right way to deal with this or do you have another suggestion?

Posted by admin  · 28-02-2017 - 12:50


Yes, using the current version is the easiest solution, but if you need to merge PDF files, you may need to change one or two objects in the MultiMerge class.

We have added a task in the todo list to consider adding some checking when there's other version of TCPDF installed.


Posted by therasim  · 28-02-2017 - 12:56

Thanks for your response. For now I'll leave this fix and wait until you integrate the check for classes already installed