dompdf ignores width attribute

maxum picture maxum · Oct 18, 2012 · Viewed 7.5k times · Source

I am trying to create a PDF that has three black boxes across the page. I have coded up the following..

  <?php
  require_once("dompdf_config.inc.php");

  $html =
    '
  <!DOCTYPE html>
  <html>
  <head>
  <meta charset="utf-8" />
  <title></title>
  <style type="text/css">

  .main
  {
  border: 0pt solid black;
  }
  .gutter
  {
  width: 100px;
  border: 1px solid black;
  }
  .card
  {
  width:50px;
  height:50px;
  border: 0px solid black;
  }
  </style>
  </head>
  <body>
  <table class="main" >
    <tbody>
      <tr>
        <td class="gutter"> </td>
        <td class="card"> </td>
        <td class="gutter"> </td>
        <td class="card"> </td>
        <td class="gutter"> </td>
      </tr>
    </tbody>
  </table>
  </body>
  </html>';

  $dompdf = new DOMPDF();
  $dompdf->load_html($html);
  $dompdf->render();
  $dompdf->stream("sample.pdf");
  ?>

The width attribute is completely ignored. I have 3 very narrow boxes in the top of the sheet.

Answer

Andrei Pasat picture Andrei Pasat · Oct 16, 2014

Try to write style width = 100% for table.