* FIX tcpdi_parser::Error() respects K_TCPDF_THROW_EXCEPTION_ERROR
tcpdi_parser::Error() called die() unconditionally, producing white
pages on PDF import failures (corrupted background, missing template)
and killing batch generation on the first bad PDF.
TCPDF already supports exception mode via K_TCPDF_THROW_EXCEPTION_ERROR,
and Dolibarr already exposes TCPDF_THROW_ERRORS_INSTEAD_OF_DIE to
control it (core/lib/pdf.lib.php). TCPDI, derived from TCPDF, never
honored it.
Changes:
- tcpdi_parser::Error(): throw \Exception when
K_TCPDF_THROW_EXCEPTION_ERROR is defined and true, otherwise die()
as before.
- commonGenerateDocument(): wrap write_file() calls in try/catch to
catch exceptions from TCPDI (and any other throwable), set
\$resultwritefile = -1 and preserve the exception message in
\$this->error.
- commonGenerateDocument(): guard error-path assignment so an already
set \$this->error (from the catch block) is not overwritten by an
empty \$obj->error.
100% backward compatible: without the constant set, behavior is
unchanged.
Assisted by Claude, maybe it needs a human verification ;)
Signed-off-by: nikube <n.zaoui@outlook.com>
* FIX Enable TCPDF/TCPDI exception mode by default
Now that tcpdi_parser::Error() honors K_TCPDF_THROW_EXCEPTION_ERROR and
commonGenerateDocument() catches write_file() exceptions, flip the
default of TCPDF_THROW_ERRORS_INSTEAD_OF_DIE from 0 to 1.
Rationale: die() in a PDF library has no legitimate production use
case. It produces white pages on web requests (user gets no message,
no way to recover) and kills batch PDF generation on the first bad
PDF. Exceptions can be caught, logged, and surfaced as normal Dolibarr
error banners.
Users who need the legacy die() behavior can opt out by setting
TCPDF_THROW_ERRORS_INSTEAD_OF_DIE = 0.
Assisted by Claude, maybe it needs a human verification ;)
Signed-off-by: nikube <n.zaoui@outlook.com>
---------
Signed-off-by: nikube <n.zaoui@outlook.com>
When mergin some old PDF we may have an infinite loop with this warning : "PHP Warning: Illegal string offset 'Type' in ./htdocs/includes/tcpdi/tcpdi_parser.php on line 706"