Could we help you? Please click the banners. We are young and desperately need the money
Dompdf already contains some default fonts but usually we need to use some custom fonts in order to make those pdf's nicer. Here we will explain how can we install and use a custom font in Dompdf version 0.8.3. Here is a link to its official github page.
Let's say that we have a folder named "fonts" and inside of that folder we have our custom font named "my-custom-font.ttf" (Image 1). File named "pdf.php" is our file used for creating a pdf with Dompdf and it contains a logic structure and content of the pdf (Image 2).
Now, we can simply include a custom font using @font-face and relative path to the font. Here is a simplified structure of pdf.php file:
<html> <head> <style> @font-face { font-family: 'MyCustomFont'; font-weight: normal; font-style: normal; font-variant: normal; src: url('fonts/my-custom-font.ttf') format('truetype'); } body { font-family: 'MyCustomFont', sans-serif; } </style> </head> <body> <p>hello world</p> </body> </html>
Tested with Dompdf version 0.8.3.