Reputation: 3498
I want to generate a PDF out of a Product. But when some images are missing, I get an TCPF ERROR.
TCPDF ERROR: [Image] Unable to get the size of the image...
Is there a usecase to go on without aborting? Already tried to catch it with the classic Exception Handler, bute doesnt work:
try {
$pdf->writeHTML($renderedView, true, 0, true, 0);
} catch (\Exception $e) {
return $e->getMessage();
}
THANKS for any help!
Upvotes: 1
Views: 4049
Reputation: 367
You can catch
the exception only if you define('K_TCPDF_THROW_EXCEPTION_ERROR', true)
There is a constant K_TCPDF_THROW_EXCEPTION_ERROR
that determines what TCPDF does in case of error.
define('K_TCPDF_THROW_EXCEPTION_ERROR', true)
will throw exceptions in case of errors
define('K_TCPDF_THROW_EXCEPTION_ERROR', false)
will echo the error and exit script execution.
Handled by method Error
in tcpdf:2921
Throw an exception or print an error message and die if the K_TCPDF_PARSER_THROW_EXCEPTION_ERROR constant is set to true.
Upvotes: 5
Reputation: 56
In general an ERROR can not be catched. You have to transform your error to an exception so you can catch it but this isnt a best practise.
Its better you test your $renderedView for the image size before you put it to TCPDF
Upvotes: 1