There is a conflict with the Print module, which also requires the TCPDF library. The error occurs in "admin / reports / status" or when trying to generate a PDF using the Print module. Disable the "Sheetnode PHPExcel" module fixes the error.

I opened an issue for the library PHPExcel (http://phpexcel.codeplex.com/workitem/17750) and the Print module (#1512730: Fatal error: Cannot redeclare class TCPDF in sites/all/libraries/tcpdf/tcpdf.php on line 155 (Sheetnode module conflict)). The Print module maintainer, @jcnventura, has already responded and said:

The print_pdf module needs to include TCPDF at that point, to find out it's version number. It seems PHPExcel is also including TCPDF at that page - possibly always.

The only way to solve this would be to use namespaces to keep them separate. However, I don't have time to setup such a complicated scenario as the one you have. If you know enough PHP you should be able to create a print_pdf namespace in which the TCPDF class can be instantiated.

If you solve it, please share the patch.

Anyway, I wonder if there is something that can be done in Sheetnode to help to resolve this conflict...

Comments

soulfroys’s picture

The only way to solve this would be to use namespaces to keep them separate.

Unfortunately, namespace is only for PHP >= 5.3.0 :(

Any other suggestions? I really appreciate any help!

infojunkie’s picture

Please change the following code in sheetnode_phpexcel.module:

function _sheetnode_phpexcel_autoload($classname) {
  include_once(variable_get('sheetnode_phpexcel_library_path', '') . '/Classes/PHPExcel.php');
  include_once(variable_get('sheetnode_phpexcel_library_path', '') . '/Classes/PHPExcel/Shared/PDF/tcpdf.php');
}

to

function _sheetnode_phpexcel_autoload($classname) {
  include_once(variable_get('sheetnode_phpexcel_library_path', '') . '/Classes/PHPExcel.php');
  if (!class_exists('TCPDF')) {
    include_once(variable_get('sheetnode_phpexcel_library_path', '') . '/Classes/PHPExcel/Shared/PDF/tcpdf.php');
  }
}

Does it work better?

soulfroys’s picture

@infojunkie, sorry for the delay in responding ...

"class_exists" has no effect because the module Sheetnode PHPExcel library includes the class before the Print module (I think). I tried to change the weight but did not work either.

@jcnventura, the Print module manteiner, commited a patch that removes the TCPDF old versions validation to improve the Sheetnode integration, but now we have a new error message (http://drupal.org/node/1512730#comment-5823306).

Well .. I'll disable the Sheetnode PHPExcel module for now and wait for the new PHPExcel version (1.7.8) that will come with better flexibility for PDF (http://phpexcel.codeplex.com/SourceControl/changeset/view/89020#1606934):

BREAKING CHANGE! In previous versions of PHPExcel library library up to and including 1.7.7,
the 3rd-party library TCPDF was bundled with PHPExcel library library for rendering PDF files
through the PDF Writer.

PHPExcel library library From 1.7.8 onwards, this will no longer be the case. The PDF Writer is
Being rewritten to allow the choice of 3rd party PDF libraries (TCPDF, mPDF, and
dompdf INITIALLY), none of Which Will be bundled with PHPExcel library library, but Which Can
be downloaded seperately from the Appropriate sites. Selection of the library to
be used, and the path to directory That library will be defined through PHPExcel library library
configuration settings, Allowing more flexibility.

Thank you very much for your attention!

infojunkie’s picture

Sheetnode PHPExcel *explicitly* needs TCPDF at this time to export HTML fragments to Rich Text (something that PHPExcel does not do automatically). So even when PHPExcel removes this dependency, Sheetnode PHPExcel will keep it. I will rework this dependency to decouple it from PHPExcel, and to try to make it compatible with the Print module.

soulfroys’s picture

PHPExcel 1.7.8 is out...
http://phpexcel.codeplex.com/releases/view/96183

Note changes to the PDF Writer: tcPDF is no longer bundled with PHPExcel, but should be installed separately if you wish to use that 3rd-Party library with PHPExcel. Alternatively, you can choose to use mPDF or DomPDF as PDF Rendering libraries instead: PHPExcel now provides a configurable wrapper allowing you a choice of PDF renderer. See the documentation, or the PDF scripts in /Tests for examples of use.

... and is no longer compatible with sheetnode:

Warning: include_once(sites/all/libraries/PHPExcel/Classes/PHPExcel/Shared/PDF/tcpdf.php): failed to open stream: No such file or directory in /srv/www/vhosts/intranet/intranet_dev/sites/all/modules/contrib/sheetnode/modules/sheetnode_phpexcel/sheetnode_phpexcel.module on line 125

soulfroys’s picture

Status: Active » Closed (duplicate)

Marking this as duplicate in favor of #1822008: PDF export doesn't work with PHPExcel 1.7.8