node-html-pdf
node-html-pdf copied to clipboard
How to use custom fonts?
First of all, thanks for that great module!
Would someone elaborate on how to use custom fonts? I've seen the business-card example with @font-face definiton, but it's unclear to me what the file-path of the font must be relative to.:
<html>
<head>
<style>
@font-face {
font-family: 'MyOpenSans';
font-style: normal;
font-weight: 400;
src: url(file://app/templates/fonts/OpenSans-Regular.ttf); <-- ?
}
</style>
...
Would appreciate some info!
You can try uploading font files to your server and try accessing from there. I am able to do this by using the following code:
@font-face { font-family: 'Aller_Rg'; src: url('https://MYS3BUCKET/assets/Aller_Rg.ttf') format('truetype') } p{ font-family: 'Aller_Rg'; font-size: 10px; }
You dont need to set base after this
I'm trying to get this running in a lambda that's locked down. How would you do this by putting the font on the file system?
I base64 the src if that helps.
@font-face {
font-family: "CustomFont";
font-style: normal;
font-weight: 700;
src: url(data:font/truetype;base64,....)
}
I base64 the src if that helps.
@font-face { font-family: "CustomFont"; font-style: normal; font-weight: 700; src: url(data:font/truetype;base64,....) }
Yes! Thank you 👏🏼
I base64 the src if that helps.
@font-face { font-family: "CustomFont"; font-style: normal; font-weight: 700; src: url(data:font/truetype;base64,....) }
Solved the problem that I was having for weeks. Thank you!
I base64 the src if that helps.
@font-face { font-family: "CustomFont"; font-style: normal; font-weight: 700; src: url(data:font/truetype;base64,....) }
I'm using the same but still have the "DejaVuSans" font inside my PDF. How can if fix this?