# FriendsOfCake / CakePdf does not read the css file

**URL:** <https://discourse.cakephp.org/t/friendsofcake-cakepdf-does-not-read-the-css-file/9980>\
**Category:** Uncategorized\
**Created:** [December 13, 2021, 6:02pm UTC](https://discourse.cakephp.org/t/friendsofcake-cakepdf-does-not-read-the-css-file/9980 "2021-12-13T18:02:16Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![dirk](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/dirk/32/2174_2.png) [@dirk](https://discourse.cakephp.org/u/dirk)\
**Post date:** [December 13, 2021, 6:02pm UTC](https://discourse.cakephp.org/t/friendsofcake-cakepdf-does-not-read-the-css-file/9980/1 "2021-12-13T18:02:16Z")

</div>

What I did:

1. installed the plugin with `composer require friendsofcake/cakepdf`

2. installed dompdf with `composer require dompdf/dompdf`

3. loaded the plugin with `./bin/cake plugin load CakePdf`

4. changed routes.php (added the last 3 lines)to

```auto
    $routes->setRouteClass(DashedRoute::class);
    $routes->scope('/', function (RouteBuilder $builder) {
        $builder->connect('/', ['controller' => 'Pages', 'action' => 'display', 'home']);
        $builder->connect('/pages/*', 'Pages::display');
        $builder->fallbacks();
    });
    $routes->prefix('Admin', function (RouteBuilder $routes) {
        $routes->fallbacks(DashedRoute::class);
    });
    //for pdf plugin:
    $routes->scope('/', function (\Cake\Routing\RouteBuilder $routes) {
      $routes->setExtensions(['pdf']);
    });

```

1. added this to bootstrap.php:

```auto
Configure::write('CakePdf', [
    'engine' => 'CakePdf.DomPdf',
    'margin' => [
        'bottom' => 15,
        'left' => 50,
        'right' => 30,
        'top' => 45
    ],
    'orientation' => 'landscape',
    'download' => true
]);

```

1. created a function in my controller

```auto
class UsersController extends AppController
{

    public function initialize(): void
    {
        parent::initialize();
        $this->loadComponent('RequestHandler');
    }

    public function beforeRender(\Cake\Event\EventInterface $event)
    {
        $this->viewBuilder()->setLayout('haas');

        if ($this->request->getAttribute('identity')->userrole_id <> 2) {
          return $this->redirect(['prefix'=>false,'controller'=>'Users','action'=>'logout']);
      }
    }

    public function createpdf($id = null)
    {
        $user = $this->Users->get($id, [
            'contain' => ['Userroles', 'Departments', 'Companyroles', 'Userstatuses'],
        ]);
        $this->viewBuilder()->setClassName('CakePdf.Pdf');
        $this->viewBuilder()->setOption(
            'pdfConfig',
            [
                'orientation' => 'portrait',
                'download' => true, // This can be omitted if "filename" is specified.
                'filename' => 'Usertestpdf_' . $id // This can be omitted if you want file name based on URL.
            ]
        );
        $this->set('user',$user);
    }//rest of users controller not shown....

```

1. created a file named “createpdf.php” in “templates/Admin/users/pdf/”. It has the same content as my view.php
2. created a file named “haas.php” in “templates/layout/pdf”:

```auto
<!DOCTYPE html>
<html>
<head>
    <?= $this->Html->charset() ?>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <?php
      echo $this->Html->css('haas.css', ['fullBase' => true]);
      echo $this->fetch('css');;
     ?>
</head>
<body>

<header class="row">
</header>
<div class="">
    <div class="text-5xl">
        <?php
          //die();
          echo $this->fetch('content')
        ?>
    </div>
</div>
</body>
</html>

```

When I go to [http://localhost/haas/admin/users/createdpdf/1](http://localhost/haas/admin/users/createdpdf/1) the pdf is created, but it is missing all the defined styles from my css named “haas.css”

Can someone see what I did wrong or where im thinking wrong?  
If you need more information, please let me know

---

<div class="post-metadata">

**Author:** ![dirk](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/dirk/32/2174_2.png) [@dirk](https://discourse.cakephp.org/u/dirk)\
**Post date:** [December 14, 2021, 4:34am UTC](https://discourse.cakephp.org/t/friendsofcake-cakepdf-does-not-read-the-css-file/9980/2 "2021-12-14T04:34:15Z")

</div>

After having some sleep, I think I found a solution:  
My css is generated with tailwind and at the moment it is really a big file which take a long time to load. After creating a new (slim) css file it works.
