Reputation: 13315
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.
Upvotes: 4
Views: 6006
Reputation: 502
Ignoring the error wouldn't be great. TCPDF when asked to use a non-existent image will simply 'die()', printing an error to the screen. This means it's outside my app's whole exception/error handling system.
Thanks for the question and proposed solution. I'm going to use this in my Symfony2 project. It makes any TCPDF problems throw an Exception to be handled by the framework since TCPDF doesn't throw Exceptions on its own. I'm using it in conjunction with the WhiteOctober Symfony2 bundle which allows you to extend the TCPDF class in 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);
}
}
Upvotes: 1
Reputation: 2981
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
Upvotes: 6