0
votes

I am using Mpdf v7 to generate a PDF file. This is my config:

$mpdfConfig =
        [
            'margin_left' => 25,
            'margin_right' => 10,
            'margin_top' => 20,
            'margin_bottom' => 20,
            'format' => 'A4-L',
            'mode' => 'win-1252',
        ];

Calling the output to save my pdf throws the following error:

Cannot find TTF TrueType font file "DejaVuSansMono.ttf" in configured font directories.' in /var/www/html/vendor/mpdf/mpdf/src/Fonts/FontFileFinder.php on line 33

I'm using Shopware 5.5.1 and work with the included mpdf library. Calling the pdf with the following code:

$mpdf = new Mpdf($mpdfConfig);
$mpdf->WriteHTML($data);
$mpdf->Output($filename, "D");

Why is the DejaVuSansMono.ttf font not found? I do not use this font. Event with defining the 'default_font' to 'Courier' I get the same error.

1

1 Answers

2
votes

Shopware is distributed with a modified version of mPDF with font files stripped (that this is a violation of its licence is another matter).

You have two or three options:

Instantiate mPDF with

$mpdf = new \Mpdf\Mpdf([
    'mode' => 'c'
]);

configuration parameter which will use internal PDF fonts only


or to download or clone mPDF (from GitHub), move the ttfonts directory to your project and add the folder to mPDF configuration:

$mpdf = new \Mpdf\Mpdf([
    'fontDir' => __DIR__ . '/ttfonts', // or similar
]);

or you can delete the vendor directory in your Shopware installation and recreate it by running composer install - that should recreate entire mPDF installatino with all fonts in the vendor directory but may cause other problems - I haven't tested this.