Hello Devs, 

In this tutorial, we will learn Laravel Dompdf Set Different font-family Example

When generating a PDF with Dompdf then it ignores fonts that are not available in its internally – Helvetica, Times-Roman, Courier, Zapf-Dingbats, Symbol.

Require to load the fonts for use in PDF creation which is not existing in Dompdf internal fonts.

Follow this step-by-step guide below. 

Step 1: Download Dompdf

Download Dompdf latest version from here

Step 2 :Table structure

CREATE TABLE `users` (
  `username` varchar(100) NOT NULL,
  `name` varchar(100) NOT NULL,
  `email` varchar(100) NOT NULL

Step 3: Configuration

Create a config.php


$host = "localhost"; /* Host name */
$user = "root"; /* User */
$password = ""; /* Password */
$dbname = "tutorial"; /* Database name */

$con = mysqli_connect($host, $user, $password,$dbname);
// Check connection
if (!$con) {
  die("Connection failed: " . mysqli_connect_error());

Step 4: Copy fonts

Create a new fonts folder at the project root.

Copy your fonts which you want to use in your pdf to the fonts folder

Step 5 :Create PDF and set font-family

include "config.php";

$html = "";
$html .= "<table border='1' width='100%' style='border-collapse: collapse;'>

$usersData = mysqli_query($con,"select * from users");
$sno = 1;
while($row = mysqli_fetch_assoc($usersData)){
    $html .= "<tr>
$html .= "</tbody></table>";

$filename = "newpdffile";

// include autoloader
require_once 'dompdf/autoload.inc.php';

// reference the Dompdf namespace
use Dompdf\Dompdf;

// instantiate and use the dompdf class
$dompdf = new Dompdf();


// (Optional) Setup the paper size and orientation
$dompdf->setPaper('A4', 'landscape');

// Render the HTML as PDF

// Output the generated PDF to Browser

May this example help you.