Php – How to over come TCPDF ERROR: [Image] Unable to get image

PHPtcpdf

I am using tcpdf v5.9.144

Which i am trying to download PDF with the given inputs if the images have bad links it is not working. Of course, It's working as it intended to be 🙂

But my issue is, Is there any way to proceed further without showing the FATAL ERROR ?

Note: Commenting the error code is not the right way, i think so.

Best Answer

class ErrorIgnoringTCPDF extends TCPDF {

public function Error($msg) {
   // unset all class variables
   $this->_destroy(true);

   // do whatever you want with $msg
   print $msg;
}

}

that will ignore all errors in your pdf. But you seriously don't want to to that! Your error is thrown, when the lib is not able to load the image (physically) it wants to display in the PDF. So you better start validating the images used in the PDF to ensure that the error itself is not thrown. I have now idea what TCPDF is doing with a non loadable image. I would guess it brakes.

think about overloading the image function and testing the existance of the image when it is added. Then throw an exception and handle the error somewhere higher in your application-stack