I am using FPDI on a PHP CMS to generate PDFs via a scheduler command. Everything works fine on my development environment (Debian 11), but when running the same code on production (Debian too), I get the following error:
Class ‘setasignFpdiFpdi’ not found | Error thrown in file /FPDF/src/Fpdi/MultiCell.php in line 5
structure Folder of FPDF (see attached screenshot)
Here is my custom MultiCell.php class:
<?php
namespace setasignFpdiMultiCell;
class MultiCell extends setasignFpdiFpdi
{
...
}
Fpdi.php :
<?php
namespace setasignFpdi;
use setasignFpdiPdfParserCrossReferenceCrossReferenceException;
use setasignFpdiPdfParserPdfParserException;
use setasignFpdiPdfParserTypePdfIndirectObject;
use setasignFpdiPdfParserTypePdfNull;
class Fpdi extends FpdfTpl
{
use FpdiTrait;
use FpdfTrait;
/**
* FPDI version
*
* @string
*/
const VERSION = '2.6.1';
}
autoload.php :
<?php
/**
* This file is part of FPDI
*
* @package setasignFpdi
* @copyright Copyright (c) 2024 Setasign GmbH & Co. KG (https://www.setasign.com)
* @license http://opensource.org/licenses/mit-license The MIT License
*/
spl_autoload_register(static function ($class) {
if (strpos($class, 'setasignFpdi\') === 0) {
$filename = str_replace('\', DIRECTORY_SEPARATOR, substr($class, 14)) . '.php';
$fullpath = __DIR__ . DIRECTORY_SEPARATOR . $filename;
if (is_file($fullpath)) {
/** @noinspection PhpIncludeInspection */
require_once $fullpath;
}
}
});
How I load FPDI in my export command :
public function exportCommand() {
require_once(ExtensionManagementUtility::extPath('myProject').'Resources/Private/FPDF/fpdf.php');
require_once(ExtensionManagementUtility::extPath('myProject').'Resources/Private/FPDF/src/autoload.php');
require_once(ExtensionManagementUtility::extPath('myProject').'Resources/Private/FPDF/src/Fpdi/MultiCell.php');
ini_set('max_execution_time', 0);
ini_set('memory_limit','-1');
...
}
what I’ve tried :
I renamed the directory from FPDF to Fpdi to match the namespace exactly. It did not fix the issue.
I checked case sensitivity on Linux. All folder and file names match their respective namespaces.
I tried to change my Multicell.php like this :
namespace setasignFpdiMultiCell;
use setasignFpdiFpdi;
class MultiCell extends Fpdi
{...}
Any help would be greatly appreciated!
PS : My project don’t use composer
