Replies: 8   Views: 120
Fatal error: cannot redeclare class fpdf joomla 3

Posted by dev-info  · 22-06-2020 - 15:13


With prenium version on joomla , we tried to install phpdocx,

But we use fpdf, fpdi and tcpdf in other place to our website, 

so when we declared :require_once '/libraries/phpdocx/classes/CreateDocx.php'; 

we have this error:Fatal error: Cannot redeclare class FPDF 

And if we comment :




others functions needed to this, that not working

Do yo ha solution for undeclrare un librarye, or check if library already loaded?

Thank you :) 

Posted by admin  · 22-06-2020 - 16:03


To avoid conflicts with PHP classes with the same name, we recommend you to use the namespaces package available in Advanced and Premium licenses instead of the classic one. As you are using a Premium license, you can download it on MYPHPDOCX page after login.

phpdocx uses custom FPDF and TCPDF classes, so they need to be used to work properly.


Posted by dev-info  · 23-06-2020 - 06:32

thank you for your reply.
There is no documentation to install the namespace version on joomla 3, do you have an idea? thank you so much

Posted by admin  · 23-06-2020 - 07:02


Please check the documentation available on , that details how to add and use external libraries with Joomla, including PHP namespace packages.

If you don't need to load the library in all pages, you could also include the main class and use it with the namespaces (using the namespaces package, not the classic one):

require_once 'path_to/Classes/Phpdocx/Create/CreateDocx.php';

$docx = new Phpdocx\Create\CreateDocx();


Posted by dev-info  · 23-06-2020 - 07:54

Thank you for your reply.

$ docx = new Phpdocx \ Create \ CreateDocx ();
$ docx-> addText ('Ceci est un test');
$ docx-> createDocx ('C: \ wamp64 \ Sample');

that works well, but when I want to use the pdf merge, it can't find it:

public static function test_merge () {
    require_once JPATH_LIBRARIES. '/phpdocx/Classes/Phpdocx/Create/CreateDocx.php';

    if (!file_exists('C:\wamp64\test3.pdf')) {

      $ merge = new MultiMerge ();
      $ merge-> mergePdf(array ('C:\wamp64\test1.pdf', 'C:\wamp64\test2.pdf'), 'C:\wamp64\test3.pdf');


I have this error: Fatal error: Class 'MultiMerge' not found

So the docx document version works well with the namespace version, but not the pdf MultiMerge .
In the classic version of phpdocx (without the namespace) any function but I have the problem of redeclaration of tcpdf.
There I no longer have a problem with class declaration TCPDF, but they cannot find the MultiMerge class


Can you help me?

Thank you



Posted by dev-info  · 23-06-2020 - 08:05

Ok that fine, 

with     $merge = new Phpdocx\Utilities\MultiMerge(); that working

the only small problem is the fact that when I merge a pdf, my environment puts in debug mode development, and therefore I see all my warning, (not really important ..) do you have an idea to remove this?
Thank you

Posted by admin  · 23-06-2020 - 08:09


We recommend you to check the included samples in the package, so you can know the namespaces you need to use for each method. For example, from examples/PdfUtilities/mergePdf/sample_1.php available in the namespaces package:

require_once 'Classes/Phpdocx/Create/CreateDocx.php';

$merge = new Phpdocx\Utilities\MultiMerge();

As you are using the namespaces package, you need to set the namespaces of the class (Phpdocx\Utilities for MultiMerge class) to be used or you can apply use keyword to set a global scope or generate an alias for the namespaces:


Posted by admin  · 23-06-2020 - 08:15


phpdocx applies error_reporting(E_ALL & ~E_STRICT & ~E_NOTICE). You can overwrite it after the code of the library using the same error_reporting function.


Posted by dev-info  · 23-06-2020 - 08:24

ok that perfect ! Thank you so much

Have a nice day

This topic is closed