mPDF errors when attempting to use Noto Emoji - Hack The Tech - Latest News related to Computer and Technology

Hack The Tech - Latest News related to Computer and Technology

Get Daily Latest News related to Computer and Technology and hack the world.

Friday, June 11, 2021

mPDF errors when attempting to use Noto Emoji

test.php:

<?php
require_once('./vendor/autoload.php');

use \Mpdf\Mpdf;
use \Mpdf\Config\ConfigVariables;
use \Mpdf\Config\FontVariables;
use \Mpdf\Output\Destination;

$defaultConfig = (new ConfigVariables())->getDefaults();
$fontDirs = $defaultConfig['fontDir'];

$defaultFontConfig = (new FontVariables())->getDefaults();
$fontData = $defaultFontConfig['fontdata'];
$mpdf = new Mpdf(
[
    'tempDir' => sys_get_temp_dir(),
    'mode' => 's',
    'fontDir' => array_merge($fontDirs, 
    [
        './static/fonts',
    ]),
    'fontdata' => $fontData +
    [
        'noto_sans' =>
        [
            'R' => 'NotoSans-Regular.ttf',
            'I' => 'NotoSans-Italic.ttf',
            'B' => 'NotoSans-Bold.ttf',
            'BI' => 'NotoSans-BoldItalic.ttf',
            'E' => 'NotoColorEmoji.ttf',
        ],
        'noto_color_emoji' =>
        [
            'R' => 'NotoColorEmoji.ttf',
        ],
    ],
    'default_font' => 'noto_sans',
    'backupSubsFont' =>
    [
        'noto_sans',
        'noto_color_emoji',
    ],
    'useSubstitutions' => true,
    'charset-in' => 'utf-8',
]);
$mpdf->WriteHTML("😋");
$temp_pdf_file = "./test.pdf";
$mpdf->Output($temp_pdf_file, Destination::FILE);

$ php test.php
Output:

PHP Notice:  Undefined offset: 48400 in /home/kenny/test/vendor/mpdf/mpdf/src/TTFontFile.php on line 4122
PHP Notice:  Undefined offset: 48401 in /home/kenny/test/vendor/mpdf/mpdf/src/TTFontFile.php on line 4123
PHP Notice:  Undefined offset: 21826 in /home/kenny/test/vendor/mpdf/mpdf/src/TTFontFile.php on line 4122
PHP Notice:  Undefined offset: 21827 in /home/kenny/test/vendor/mpdf/mpdf/src/TTFontFile.php on line 4123
PHP Notice:  Undefined offset: 53970 in /home/kenny/test/vendor/mpdf/mpdf/src/TTFontFile.php on line 4122
PHP Notice:  Undefined offset: 53971 in /home/kenny/test/vendor/mpdf/mpdf/src/TTFontFile.php on line 4123
PHP Notice:  Undefined offset: 18189 in /home/kenny/test/vendor/mpdf/mpdf/src/TTFontFile.php on line 4122
PHP Notice:  Undefined offset: 18190 in /home/kenny/test/vendor/mpdf/mpdf/src/TTFontFile.php on line 4123
PHP Warning:  unpack(): Type n: not enough input, need 2, have 0 in /home/kenny/test/vendor/mpdf/mpdf/src/TTFontFile.php on line 4379
PHP Warning:  unpack(): Type n: not enough input, need 2, have 0 in /home/kenny/test/vendor/mpdf/mpdf/src/TTFontFile.php on line 4379
PHP Warning:  unpack(): Type n: not enough input, need 2, have 0 in /home/kenny/test/vendor/mpdf/mpdf/src/TTFontFile.php on line 4379
PHP Warning:  unpack(): Type n: not enough input, need 2, have 0 in /home/kenny/test/vendor/mpdf/mpdf/src/TTFontFile.php on line 4379
PHP Warning:  unpack(): Type n: not enough input, need 2, have 0 in /home/kenny/test/vendor/mpdf/mpdf/src/TTFontFile.php on line 4379
PHP Warning:  unpack(): Type n: not enough input, need 2, have 0 in /home/kenny/test/vendor/mpdf/mpdf/src/TTFontFile.php on line 4379
PHP Warning:  unpack(): Type n: not enough input, need 2, have 0 in /home/kenny/test/vendor/mpdf/mpdf/src/TTFontFile.php on line 4379
PHP Warning:  unpack(): Type n: not enough input, need 2, have 0 in /home/kenny/test/vendor/mpdf/mpdf/src/TTFontFile.php on line 4379
PHP Notice:  Undefined offset: 48400 in /home/kenny/test/vendor/mpdf/mpdf/src/TTFontFile.php on line 4365
PHP Notice:  Undefined offset: 48401 in /home/kenny/test/vendor/mpdf/mpdf/src/TTFontFile.php on line 4366
PHP Notice:  Undefined offset: 21826 in /home/kenny/test/vendor/mpdf/mpdf/src/TTFontFile.php on line 4365
PHP Notice:  Undefined offset: 21827 in /home/kenny/test/vendor/mpdf/mpdf/src/TTFontFile.php on line 4366
PHP Notice:  Undefined offset: 53970 in /home/kenny/test/vendor/mpdf/mpdf/src/TTFontFile.php on line 4365
PHP Notice:  Undefined offset: 53971 in /home/kenny/test/vendor/mpdf/mpdf/src/TTFontFile.php on line 4366
PHP Notice:  Undefined offset: 18189 in /home/kenny/test/vendor/mpdf/mpdf/src/TTFontFile.php on line 4365
PHP Notice:  Undefined offset: 18190 in /home/kenny/test/vendor/mpdf/mpdf/src/TTFontFile.php on line 4366

test.pdf has a single "tofu" character.

mPDF is v8.0.11, PHP is v7.2.24. Changing the PHP version is not feasible at this time. Characters that are covered by ASCII work fine. CJK characters do not, but I don't have fonts for those yet, so that isn't surprising.



source https://stackoverflow.com/questions/67926735/mpdf-errors-when-attempting-to-use-noto-emoji

No comments:

Post a Comment