Skip to content
This repository has been archived by the owner on Aug 22, 2023. It is now read-only.

custom font not working on version 2 with mpdf 7 #81

Closed
1razzaghi opened this issue Jan 14, 2018 · 4 comments
Closed

custom font not working on version 2 with mpdf 7 #81

1razzaghi opened this issue Jan 14, 2018 · 4 comments

Comments

@1razzaghi
Copy link

hi i added the custom font in the config file=> pdf.php
but it is not working
it is also working on the other project with older version laravel-pdf with mpdf 6.x

@1razzaghi
Copy link
Author

1razzaghi commented Jan 14, 2018

i fix the problem myself
the problem is in addCustomFontsConfig function on Pdf.php file in \vendor\niklasravnsborg\laravel-pdf\src\LaravelPdf\Pdf.php directory.

first bug is in the if condition if (!Config::has('pdf.font_path') || !Config::has('pdf.font_data'))
there is no any config value for pdf.font_path and pdf.font_data ! so the condition return the $mpdf_config variable without any changes and add custom font

for solving this condition issue change the condition to
if (!Config::has('pdf.custom_font_path') || !Config::has('pdf.custom_font_data'))

the second bug is assigning value to $mpdf_config['fontDir'] and $mpdf_config['fontdata'] with the wrong config value that are'nt exist.
for solving this just change the value of two variable with the correct config value :

$mpdf_config['fontDir'] = array_merge($fontDirs, [Config::get('pdf.custom_font_path')]); $mpdf_config['fontdata'] = array_merge($fontData, Config::get('pdf.custom_font_data'));

@chireenjavier
Copy link

Hi 1razzaghi,
I have a similar issue. I tried to fix this with your solution, howver nothing happened for me. Where can o find the
$mpdf_config['fontdata'] = array_merge($fontData, Config::get('pdf.custom_font_data')); ?

Thanks :)

@1razzaghi
Copy link
Author

1razzaghi commented Feb 19, 2018

the problem is in addCustomFontsConfig function on Pdf.php file in \vendor\niklasravnsborg\laravel-pdf\src\LaravelPdf\Pdf.php directory

@dcblogdev
Copy link

hey guys did you try using font_path instead of customer_font_path ?

I've been able to add a custom font just by adding this to the config:

    'font_path' => public_path('fonts'),
    'font_data' => [
        'barcode_font' => [
            'R'  => 'c39hrp36dltt.ttf',    // regular font
        ]
    ]

cryptoBOOOOM added a commit to cryptoBOOOOM/laravel-pdf that referenced this issue Oct 8, 2018
Changed custom fonts config according to niklasravnsborg#81 (comment)

(Now it works again)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants