Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

jukia's avatar
Level 1

how to add css in dompdf

i am using inline css and internal css but font family not picking in dompdf

0 likes
6 replies
anilkumarthakur60's avatar

you can add your CSS styles in an external file and reference it in the head section of your HTML document using the link tag.

<head>
  <link rel="stylesheet" href="path/to/your/styles.css">
</head>

Finally, when rendering the HTML document with DOMPDF, make sure to set the isRemoteEnabled option to true to allow loading of external resources such as CSS files. Here's an example PHP code snippet that shows how to use DOMPDF with CSS styles:

use Dompdf\Dompdf;

// create a new instance of Dompdf
$dompdf = new Dompdf();

// load your HTML content with CSS styles
$html = '<html><head>
//css link
</head><body>Hello, world!</body></html>';
$dompdf->loadHtml($html);

// set the PDF rendering options
$dompdf->setPaper('A4', 'portrait');

// enable remote file access (e.g., to load external CSS files)
$dompdf->setOptions([
    'isRemoteEnabled' => true,
]);

// render the PDF document
$dompdf->render();

// output the PDF document to the browser or save it to a file
$dompdf->stream('document.pdf');
1 like
jukia's avatar
Level 1

no css is picking please help me Argument 1 passed to Dompdf\Dompdf::setOptions() must be an instance of Dompdf\Options, array given, called in D:\xamp2\htdocs\lastpro\app\Http\Controllers\FormController.php on line 293 and defined

jukia's avatar
Level 1

if i using external css the file is loading not making pdf when a use internal css the file work but not getting style

jukia's avatar
Level 1

i have one problem all the styling is is applying but font family not applying in dompdf

jukia's avatar
Level 1

i have tried all way but the f_____________________k font family not changing in dompdf

Please or to participate in this conversation.