Commit graph

12 commits

Author SHA1 Message Date
nikube
d5f773158e
FIX TCPDI: honor K_TCPDF_THROW_EXCEPTION_ERROR and enable exceptions by default (#37827)
* 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>
2026-04-11 18:01:59 +02:00
ldestailleur
5ebd1921ed NEW Upgrade TCPDI 1.0 into TCPDI 1.1 + custom fixes 2025-03-03 05:11:14 +01:00
Laurent Destailleur
21624863bd Fix tcpdf 2023-07-03 15:38:02 +02:00
Sylvain Legrand
12cd6c0ddf Fix tcpdi_parser infinite loop
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"
2023-02-20 18:44:36 +01:00
Philippe GRAND
6c61b80778 fix : Warning: Trying to access array offset on value of type bool in /home/httpd/vhosts/aflac.fr/domains/dev.aflac.fr/httpdocs/includes/tcpdi/tcpdi_parser.php on line 1376 2023-02-05 14:57:36 +01:00
Laurent Destailleur
f567d41055 Fix php8 2020-09-08 05:16:37 +02:00
Alexandre SPANGARO
02dbc11f98 Move Gnu.org to https 2019-09-23 21:55:30 +02:00
De Coninck Laurent
59307165ce fix the pdf merge
fix the pdf merge.

[See: #9824]
2018-10-21 19:45:33 +02:00
Laurent Destailleur
7ceb3cb62a FIX Avoid error 500 if phpexcel is disabled 2016-10-22 16:53:22 +02:00
Raphaël Doursenaud
c3ed30ffd8 Moved to new package for TCPDF
Previous one has been deprecated by upstream
2015-11-09 12:21:08 +01:00
Raphaël Doursenaud
e0312d048b Install TCPDF from composer 2015-09-04 19:06:04 +02:00
Laurent Destailleur
2f24622a7c NEW: Introduce TCPDI as replacement of FPDI. 2015-03-02 01:38:40 +01:00