pdf icon indicating copy to clipboard operation
pdf copied to clipboard

PdfResponse::mpdfConfig does not allow fontDir

Open JanKalach opened this issue 1 year ago • 1 comments

Mpdf can be created with config param fontDir.

$mpdf = new Mpdf([
    'tempDir' => $myTempDir,
    'fontDir' => [$myCustomFontDir],
    'fontData' =>[$myCustomFontData],
    'default_font' => 'poppins',
]);

When I add mpdfConfig with fontDir to PdfResponse

$PdfResponse = new PdfResponse();
$PdfResponse->mpdfConfig = [
    'tempDir' => $myTempDir,
    'fontdata' => [$myCustomFontData],
    'fontDir' => [$myCustomFontDir],
    'default_font' => 'poppins',
];
$mpdf = $PdfResponse->getMPDF();

I become error: Cannot write to an undeclared property [Mpdf\Mpdf]::$fontDir [Mpdf\Mpdf]::$fontDir is set as private property (vendor/mpdf/mpdf/src/Mpdf.php:283)

Using of Mpdf methods AddFontDirectory and AddFont do not apply changes, or font is not applied. Fonts are used when the necessary configuration options are added to the object creation.

JanKalach avatar Jul 25 '23 14:07 JanKalach

@JanKalach This is my working solution:

        $mpdf = $this->pdf->getMPDF();
        $mpdf->fontdata += [
            'arial' => [
                'R' => 'arial-regular.ttf',
                'B' => 'arial-bold.ttf',
                'useOTL' => 0xff,
            ],
        ];
        $mpdf->AddFontDirectory(__DIR__ . '/font');
        $mpdf->AddFont('arial');
        $mpdf->SetFont('arial');

radimvaculik avatar May 05 '24 05:05 radimvaculik