Showing posts with label Custom-Font. Show all posts
Showing posts with label Custom-Font. Show all posts

Friday, April 14, 2017

Laravel DOM-PDF include custom font

Laravel is a strong php based framework today. If you have not install dompdf yet, follow this link to install dompdf in your project. After installation of dompdf follow the below steps:

1. Create a folder named "fonts" under root folder.

2. Download your preferred font and put them in "fonts" directory.

3. Now need to add font as font-face in your css file as follows:


@font-face {
    font-family: cedarville-font-family;
    src: url("{{ asset('fonts/Cedarville-Cursive.ttf') }}");
    font-weight: normal;
}

4. Now you need to set font-family to see desired output, below is a full example of view page:



<!DOCTYPE html>
<html lang="en" >
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta content='width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no' name='viewport'>
    <title>First Laravel DOM PDF</title>
    <style>
        @font-face {
            font-family: cedarville-font-family;
            src: url("{{ asset('fonts/Cedarville-Cursive.ttf') }}");
            font-weight: normal;
        }
        @font-face {
            font-family: cedarville-font-family;
            src: url("{{ asset('fonts/Cedarville-Cursive.ttf') }}");
            font-weight: bold;
        }
    </style>
</head>
<body>
<div style="font-family: cedarville-font-family;">Test PDF</div>
</body>
</html>

5. And now your pdf would look like: