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

Custom font not loading #11

Closed
kinger251285 opened this issue Mar 11, 2019 · 4 comments
Closed

Custom font not loading #11

kinger251285 opened this issue Mar 11, 2019 · 4 comments

Comments

@kinger251285
Copy link

Hi

I have followed your docs and have the config file as below:

`<?php

return [
'mode' => 'utf-8',
'format' => 'A4',
'default_font_size' => '12',
'default_font' => 'sans-serif',
'margin_left' => 10,
'margin_right' => 10,
'margin_top' => 10,
'margin_bottom' => 10,
'margin_header' => 0,
'margin_footer' => 0,
'orientation' => 'P',
'title' => 'Laravel mPDF',
'author' => '',
'watermark' => '',
'show_watermark' => false,
'watermark_font' => 'sans-serif',
'display_mode' => 'fullpage',
'watermark_text_alpha' => 0.1,
'custom_font_dir' => base_path('resources/fonts/'), // don't forget the trailing slash!
'custom_font_data' => [
'Quantify' => [
'R' => 'Quantify.ttf' // regular font
]
]
];`

however the font does not display at all. Only the default san serif font.

Inline style in my pdf balde:

` @font-face {
font-family: 'Quantify';
}

body {
font-family: 'Quantify', sans-serif;
letter-spacing: 2px;
padding-right: 0 !important;
}`

Tried mapping to my standard fonts location in storage and tried moving that folder to resources as defined above. But no difference.

Currently developing on local homestead setup if this makes a difference?

Any help appreciated.

@mccarlosen
Copy link
Owner

mccarlosen commented Mar 12, 2019

Change the custom_font_data settings to this:

'custom_font_data' => [
    'quantify' => [
        'R' => 'Quantify.ttf' // regular font
     ]
],

Within your view, remove the @font-face and change your font-family by this:

body {
    font-family: 'quantify', sans-serif;
    letter-spacing: 2px;
    padding-right: 0 !important;
}

For some reason the name of the font only accepts lowercase...'quantify' => [

I hope it has been helpful, ah and do not forget to refresh the cache...

In my example, just apply the font to the h1 tag.

body h1 {
    font-family: 'quantify', sans-serif;
}

image

@kinger251285
Copy link
Author

Brilliant, did the trick. Had to move the letter spacing to my table class too to work otherwise this was ignored but fully working now. Thanks for the great package and quick response.

@hannanstd
Copy link

best package for persian characters. after alot of hours finaly this package helped me.
an note for arabic and persain fonts. if your characteres are seperately and not conneted use below config:

mpdf/mpdf#85 (comment)

@karunkshrestha
Copy link

I am having the similar issue where the custom fonts are not picked up.
config:
image

fonts:
image

load view:
$pdf = PDF::loadView('emails.test.view',['data' => $this->data]);

Result: defaults to dejavu font
image

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

No branches or pull requests

4 participants