DOMPDF does not work with external css file


I'm using Zend Framework and DOMPDF library. When I test it with inline css everything works perfectly. But when I tried to move css code to the external file rules are not applied to the html page.

Here is my code.

  1. Code of controller's action, which generate pdf



    $html = $this->view->render('index/dom.phtml');

    $dompdf = new DOMPDF();

    $pdfContent =   $dompdf->output();

    file_put_contents('sample.pdf', $pdfContent);


2.Code of corresponding view (index/dom.phtml)

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"     "">
<html xmlns="">
    <link type="text/css" href="/themes/css/pdf.css" rel="stylesheet"   media="screen"/>

    <div>Tamara testing</div>
    <table border="1">
            <th>Column 1</th>
            <th>Column 2</th>
            <td>Value 1</td>
            <td>Value 2</td>


3.And my css file:

div {color: red;}

How to make it works?


To make it works I changed the following things:

1.In controller's action add base path for external files


2.In view change href attribute of the link tag. Make it relative to the base path set in step 1.

<link type="text/css" href="pdf.css" rel="stylesheet" />

This has in fact nothing to do with Zend Framework, but you need to supply DomPDF the right path to load the "external" files from.

$dompdf = new DOMPDF();
$dompdf->set_base_path(realpath(APPLICATION_PATH . '/path/to/css/'));

See also the manual of DomPDF for this feature.