How to end TCPDF ERROR: [Image] Failed to get image?

I am using tcpdf v5.9.144

What I'm trying to download a PDF with these inputs, if the images have bad links, they do not work. Of course, it works as planned :-)

But my problem: Is there a way to continue further without showing FATAL ERROR ?

Note: Commenting the error code is the wrong way, I think so.

+4
source share
2 answers
class ErrorIgnoringTCPDF extends TCPDF { public function Error($msg) { // unset all class variables $this->_destroy(true); // do whatever you want with $msg print $msg; } 

}

which will ignore all errors in your pdf. But you really don't want to! Your error occurs when lib cannot load the image (physically) that it wants to display in a PDF file. Therefore, you better start checking the images used in the PDF to make sure that the error itself is not selected. Now I know what TCPDF does with a non-uploadable image. I would suggest that it slows down.

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

+6
source

Ignoring the error will not be big. TCPDF, when asked to use a non-existent image, simply "die ()", printing an error on the screen. This means that it is outside my application exception and error handling system.

Thanks for the question and the proposed solution. I am going to use this in my Symfony2 project. This causes any TCPDF problems to raise an exception that must be handled by the infrastructure, because TCPDF does not throw exceptions on its own. I use it in conjunction with the WhiteOctober Symfony2 package, which allows you to extend the TCPDF class this way.

 namespace Acme\MyBundle\ClassExtensions; class ExceptionThrowingTCPDF extends \TCPDF { public function Error($msg) { // Clean up: unset class variables $this->_destroy(true); throw new \Exception('PDF generation failed: ' . $msg); } } 
+1
source

Source: https://habr.com/ru/post/1391447/


All Articles