mreg-archive/fpdi

Bridge to tecnickcom/tcpdf not working

Closed this issue · 1 comments

Auto suggesting for included tecnickcom/tcpdf not working because class_exists('\\TCPDF', false) always return false. Even if tecnickcom/tcpdf include before itbz/fpdi in composer.json
https://github.com/hanneskod/fpdi/blob/1.6.1/src/fpdi_bridge.php#L19

Hi and thanx for reporting!

class_exists('\\TCPDF', false) returns false because the TCPDF class has not yet been defined. The order of listed dependencies in composer.json does not matter in this situation. What you need to do is to somehow trigger the inclusion of the TCPDF class before you create your FPDI object.

// This by default will create a fpdf-based object
$fpdf_base = new \fpdi\FPDI;

// This will trigger the inclusion of TCPDF by hitting the autoloader
if(!class_exists('TCPDF')) {
    die('TCPDF not registered in autoloader');
}

// Now FPDI will be tcpdf based
$tcpdf_base = new \fpdi\FPDI;

The fact that the behaviour of FPDI is dependant on global state in this manner is definitely not ideal. But it's the result of structural decisions made at Setasign and nothing I can correct I am afraid.