CSS not working with DOMPDF

dompdf v0.5.x does not support floats. v0.6.0 does, though it is still an experimental feature that has to be enabled in the configuration. After testing your document I can say that dompdf doesn't handle it very well. If you want to stick with dompdf you might consider tables since your document is somewhat tabular in nature.


Simple solution is, Put your css in separate (.php) or any other server scripting file and include it in your pdf file. eg. You have pdf.blade.php file for pdf

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">
    {{-- <link rel="icon" href="/favicon.ico"> --}}

    <title>Starter Template for Bootstrap</title>
<style type="text/css">
@include('pdf.style')
</style>
  </head>
  <body>

    <nav class="navbar navbar-inverse navbar-fixed-top">
      <div class="container">
        <div class="navbar-header">
          <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
            <span class="sr-only">Toggle navigation</span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
          </button>
          <a class="navbar-brand" href="#">Project name</a>
        </div>
        <div id="navbar" class="collapse navbar-collapse">
          <ul class="nav navbar-nav">
            <li class="active"><a href="#">Home</a></li>
            <li><a href="#about">About</a></li>
            <li><a href="#contact">Contact</a></li>
          </ul>
        </div><!--/.nav-collapse -->
      </div>
    </nav>

    <div class="container">

      <div class="starter-template">
        <h1>Bootstrap starter template</h1>
        <p class="lead">Use this document as a way to quickly start any new project.<br> All you get is this text and a mostly barebones HTML document.</p>
      </div>

    </div><!-- /.container -->
  </body>
</html>

Suppose you have css file style.css, So next step is to copy your css file content and paste it in new style.blade.php And you almost done!!

Now include it in your pdf file eg.

<style>
  @include('style')
</style>    

thats the simple trick worked for me.


Internal stylesheet can be created by including the styles in between <style> element not <styles> element.

below stmt is wrong:

<styles>...</styles>

It should be :

<style> ... </style>

and inline styles should given as shown below:

<div class="className" style="color:red;text-align: left;">

and external style sheet should be included as shown below:

<link rel="stylesheet" type="text/css" media="screen" href="styles.css" />

If external style sheet is not working then check the source file path.