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

From PHP 7.4, 'helvetica' MUST be used in example_014.php #568

Closed jausions closed 1 year ago

jausions commented 1 year ago

If we create some code based on _example014.php and remplace the font used by something else than helvetica (at lines 74, 88, 92), then a notice is raised from PHP 7.4+.

Notice: Trying to access array offset on value of type bool in <path>\TCPDF\tcpdf.php on line 9922

Warning: Cannot modify header information - headers already sent by (output started at <path>\TCPDF\tcpdf.php on line 7726
<strong>TCPDF ERROR: </strong>Some data has already been output to browser, can't send PDF file

We can see the problem is with a hard-coded helvetica font name at line 9921 of tcpdf.php

It is probably safer to not modify the tcpdf.php file and just inform the user in the _example014.php file that helvetica must be used at line 74. I will do a PR.

jausions commented 1 year ago

Same issue for _example054.php which is also a form example.

jausions commented 1 year ago

And for some reason, _example052.php (encryption) also requires helvetica for the same line number 9921 of tcpdf.php

jausions commented 1 year ago

For info, I am trying to build a set of rendered examples that could be used as a reference for non-regression tests when corrections are applied to the code base.

However, to be cross-environment independent and have the same rendering, the fonts used should be non-commercial ones and be available on most operating systems. Sadly, Helvetica is a commercial font, so GNU's FreeFont and DéjàVu are viable alternative in my view. When I tried to switched font for the aforementioned examples, the notice popped up on PHP 7.4+.