title: Using Dompdf to view .pdf from CakePHP 2 page
body: <p>I have just downloaded <code>dompdf-0.6.1</code> and want to use it in my CakePHP 2.0.5 application.</p>
  
  <p>I have included <code>Router::parseExtensions('json', 'pdf');</code> in routes.php and created a default.ctp in app -> View -> Layouts.</p>
  
  <pre><code>&lt;?php
  
  require_once(APP . 'Vendor' . DS . 'dompdf' . DS . 'dompdf_config.inc.php');
  spl_autoload_register('DOMPDF_autoload');
  $dompdf = new DOMPDF();
  $dompdf-&gt;set_paper = 'A4';
  $dompdf-&gt;load_html(utf8_decode($content_for_layout), Configure::read('App.encoding'));
  $dompdf-&gt;render();
  echo $dompdf-&gt;output();
  </code></pre>
  
  <p>I want to allow a user to view an income statement as a .pdf file - which can be printed. The income statement takes the parameters of startDate and endDate for generation.</p>
  
  <p>The file below is the income_statement.ctp. What do I need to do in order to allow a user to view the statement as .pdf by pressing on a link on the browser page?</p>
  
  <pre><code>.......some code...... 
  
   &lt;div style="text-align:  center"&gt;
  
          &lt;h1&gt;&lt;?php echo $this-&gt;Session-&gt;read("Business.name"); ?&gt;&lt;br&gt;Income Statement&lt;/h1&gt;
          &lt;h3&gt;
              For period starting &lt;?php echo $startDate; ?&gt; to &lt;?php echo $endDate; ?&gt;
          &lt;/h3&gt;
          &lt;table align="center" width="400px;"&gt;
              &lt;tr&gt;
                  &lt;th style="text-align: left;" colspan="2"&gt;Revenue&lt;/td&gt;
              &lt;/tr&gt;
             ........code.........
                  &lt;td style="text-align: left;"&gt;
                      &lt;?php
                      $space = "&amp;nbsp;";
                      for ($i = 0; $i &lt; 12; $i++)
                          echo $space;
                      ?&gt;
                      &lt;b&gt;Total Operating Expenses&lt;/b&gt;
                  &lt;/td&gt;
                  &lt;td style="text-align: right;"&gt;&lt;b&gt;&lt;?php echo number_format($totalExpenses + $saleDiscount, 2); ?&gt;&lt;/b&gt;&lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;th style="text-align: right"&gt;&lt;?php echo $totalDescription; ?&gt;&lt;/th&gt;
                  &lt;th style="text-align: right"&gt;&lt;?php echo number_format($net, 2); ?&gt;&lt;/th&gt;
              &lt;/tr&gt;
          &lt;/table&gt;      
  
      ....Link for view as pdf.....
      &lt;/div&gt;
  </code></pre>