Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PdfResponse::mpdfConfig does not allow fontDir #59

Open
JanKalach opened this issue Jul 25, 2023 · 1 comment
Open

PdfResponse::mpdfConfig does not allow fontDir #59

JanKalach opened this issue Jul 25, 2023 · 1 comment

Comments

@JanKalach
Copy link

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.

@radimvaculik
Copy link
Member

@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');

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants