pdf
pdf copied to clipboard
PdfResponse::mpdfConfig does not allow fontDir
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 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');