tecnickcom / TCPDF

Official clone of PHP library to generate PDF documents and barcodes
https://tcpdf.org
Other
4.18k stars 1.51k forks source link

Forced line break and German umlaut #464

Open hf2094 opened 2 years ago

hf2094 commented 2 years ago

Hello, I use TCPDF to generate PFD-reports from nuBuilder Reports on an Arch Linux system with AMD x86_64, 4GB RAM, Kernel 5.15.12 and PHP 8.0.14.

In my PDF-reports I have a small text field with size=80px, font dejavusanscondensed, fontsize 10. When I put one test string in this field, e.g. "Wanderstöcke" then TCPDF automatically performs a forced line break winthin the text. If this line break is just in front of the german umlaut (ö here, but i can use any other umlaut), then TCPDF terminates the PDF-generation and puts a message in /var/log/httpd/error_log :

[Tue Jan 04 19:35:49.820175 2022] [php:error] [pid 6823] [client 127.0.0.1:46818] PHP Fatal error: Uncaught TypeError: array_map(): Argument #2 ($array) must be of type array, bool given in /srv/http/nubuilder/core/libs/tcpdf/include/tcpdf_fonts.php:2004 Stack trace:

0 /srv/http/nubuilder/core/libs/tcpdf/include/tcpdf_fonts.php(2004): array_map()

1 /srv/http/nubuilder/core/libs/tcpdf/tcpdf.php(6394): TCPDF_FONTS::UTF8StringToArray()

2 /srv/http/nubuilder/core/libs/tcpdf/tcpdf.php(5971): TCPDF->Write()

3 /srv/http/nubuilder/core/nurunpdf.php(948): TCPDF->MultiCell()

4 /srv/http/nubuilder/core/nurunpdf.php(178): nuPrintField()

5 /srv/http/nubuilder/core/nurunpdf.php(78): nuPrintReport()

6 /srv/http/nubuilder/core/nurunpdf.php(23): nuRunReportId()

7 {main}

thrown in /srv/http/nubuilder/core/libs/tcpdf/include/tcpdf_fonts.php on line 2004, referer: http://achleiten/minadmin/

There is no problem, when I change the text of the field so that the linebreak in not in front of the umlaut or on any other position in the text. The problem is bound to PHP8. When I use PHP7 there is also no problem.

Thanks for your attention Yours Hf2094

sgiehl commented 2 years ago

The problem seems to be here: https://github.com/tecnickcom/TCPDF/blob/bf02c1cb620533be4b7a85eebdda464cf00fd080/include/tcpdf_fonts.php#L2002-L2004

TCPDF_STATIC::pregSplit might return false, if an error occurs within the preg_split it performs. In PHP 7 that only triggered a warning, while PHP 8 now throws an error.