title: Convert page to PDF using dompdf
body: <p>I am trying to convert a PHP page to PDF using dompdf, but I'm not sure of the best way to do it. I have wrote my page how I would like it to be presented in standard HTML/PHP, and would like it to be displayed like so, just as a PDF:</p>
  
  <p><img src="https://i.stack.imgur.com/tbpGO.png" alt="Desired output"></p>
  
  <p>My PHP code is below. I believe I need to put my code into the <code>$html</code> variable to parse that into dompdf, but I'm a bit of a PHP newbie, so would appreciate some help as to what the best way to achieve this is. Obviously, the styling of the page is all being brought in from external CSS files, so I'm not sure if that's an issue or not?</p>
  
  <pre><code>&lt;?php
      include("checklog.php"); 
      require_once("watchlist-controller.php");
      require_once("dompdf/dompdf_config.inc.php");
      $html = 
  ?&gt;
  &lt;!DOCTYPE html&gt;
      &lt;head&gt;
          &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"&gt;
          &lt;link rel="shortcut icon" href="img/fav.ico"&gt;
          &lt;link rel="apple-touch-icon" href="img/apple-touch-icon.png"&gt;
          &lt;title&gt;Screening - Your ticket to your movies - &lt;?php echo $watchlist_name; ?&gt;&lt;/title&gt;
          &lt;meta name="description" content="Screening is a brand new take on the traditional movie database, fusing social networking and multimedia to provide a clear, concise experience allowing you to share your favourite movies, and discover new classics."&gt;
          &lt;meta name="keywords" content="Movies, Films, Screening, Discover, Watch, Share, experience, database, movie database, film database, share film, share films, discover film, discover films, share movie, share movies, discover movie, discover movies"&gt;
  
          &lt;!-- Bootstrap --&gt;
          &lt;link href="css/bootstrap.css" rel="stylesheet" media="screen"&gt;
          &lt;link href="css/bootstrap-responsive.css" rel="stylesheet"&gt;
          &lt;link href="css/custom-bootstrap.css" rel="stylesheet"&gt;
          &lt;link rel="stylesheet" href="fonts.css" type="text/css" /&gt;
          &lt;link rel="stylesheet/less" type="text/css" href="css/stylesheet.less" /&gt;
          &lt;script src="js/less-1.3.3.min.js" type="text/javascript"&gt;&lt;/script&gt;
          &lt;script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.8/jquery.min.js"&gt;&lt;/script&gt;
          &lt;script src="js/bootstrap.min.js"&gt;&lt;/script&gt;
      &lt;/head&gt;
  
      &lt;body&gt;
          &lt;div class="container"&gt;&lt;?php 
              require_once ("header.php");?&gt;
              &lt;div id="main" class="well main-content"&gt;
                  &lt;p class="page-title"&gt;&lt;?php echo $watchlist_name; ?&gt;&lt;/p&gt;
                  &lt;div class="row-fluid"&gt;
                      &lt;section class="span12 watchlist-holder film-list"&gt;&lt;?php
                          if (count($films) == 0) {?&gt;
                              &lt;div class="alert alert-info"&gt;This Watchlist is empty! Why not visit a movie page to add something to it?&lt;/div&gt;&lt;?php
                          } else {?&gt;
                              &lt;ul class="unstyled"&gt;&lt;?php
                                  foreach($films as $key =&gt; $film_item) {
                                      include("watchlist-film-controller.php");?&gt;
                                      &lt;li class="well list-item clearfix"&gt;
                                          &lt;div class="row-fluid"&gt;
                                              &lt;a href="movie.php?id=&lt;?php echo $rt_id; ?&gt;" class="span1 pull-left" title="&lt;?php echo $title; ?&gt;"&gt;&lt;img src="&lt;?php echo $poster_thumb; ?&gt;" alt="&lt;?php echo $title; ?&gt; poster" title="&lt;?php echo $title; ?&gt; poster" /&gt;&lt;/a&gt;
  
                                              &lt;div class="span11 movie-info"&gt;
                                                  &lt;p class="search-title"&gt;&lt;a href="movie.php?id=&lt;?php echo $film_item['film_id']; ?&gt;" title="&lt;?php echo $title; ?&gt; (&lt;?php echo $year; ?&gt;)"&gt;&lt;?php echo $title; ?&gt;&lt;/a&gt; &lt;small&gt;(&lt;?php echo $year; ?&gt;)&lt;/small&gt;&lt;/p&gt;&lt;?php
  
                                                  if ($critics_consensus == "") {?&gt;
                                                      &lt;p class="watchlist-synopsis"&gt;No overview available&lt;/p&gt;&lt;?php
                                                  } else {?&gt;
                                                      &lt;p class="watchlist-synopsis"&gt;&lt;?php echo $critics_consensus; ?&gt;&lt;/p&gt;&lt;?php
                                                  }?&gt;
                                              &lt;/div&gt;
                                          &lt;/div&gt;
                                      &lt;/li&gt;&lt;?php
                                  }?&gt;
                              &lt;/ul&gt;&lt;?php
                          }?&gt;
                      &lt;/section&gt;
                  &lt;/div&gt;
              &lt;/div&gt;&lt;?php
              include 'footer.html'; ?&gt;
          &lt;/div&gt;
      &lt;/body&gt;
  &lt;/html&gt;&lt;?php
  $dompdf = new DOMPDF();
  $dompdf-&gt;load_html($html);
  $dompdf-&gt;render();
  $dompdf-&gt;stream("sample.pdf");?&gt;
  </code></pre>
  
  <p><strong>Update</strong></p>
  
  <p>Based on BrianS's comment (thank you!), my new code looks like below, however I'm now getting just a plain blank page when trying to view the Watchlist. I've tested it without the dompdf stuff, and the page appears perfectly, showing all the information I want it to show, and presented correctly. I've also replaced the LESS file with CSS and removed all the JS.</p>
  
  <pre><code>&lt;?php
      include("checklog.php");
      require_once("watchlist-controller.php");
      require_once("dompdf/dompdf_config.inc.php");
      ob_start();
  ?&gt;
  &lt;!DOCTYPE html&gt;
      &lt;head&gt;
          &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"&gt;
          &lt;link rel="shortcut icon" href="img/fav.ico"&gt;
          &lt;link rel="apple-touch-icon" href="img/apple-touch-icon.png"&gt;
          &lt;title&gt;Screening - Your ticket to your movies - &lt;?php echo $watchlist_name; ?&gt;&lt;/title&gt;
          &lt;meta name="description" content="Screening is a brand new take on the traditional movie database, fusing social networking and multimedia to provide a clear, concise experience allowing you to share your favourite movies, and discover new classics."&gt;
          &lt;meta name="keywords" content="Movies, Films, Screening, Discover, Watch, Share, experience, database, movie database, film database, share film, share films, discover film, discover films, share movie, share movies, discover movie, discover movies"&gt;
  
          &lt;!-- Bootstrap --&gt;
          &lt;link href="css/bootstrap.css" rel="stylesheet" media="screen"&gt;
          &lt;link href="css/bootstrap-responsive.css" rel="stylesheet"&gt;
          &lt;link href="css/custom-bootstrap.css" rel="stylesheet"&gt;
          &lt;link rel="stylesheet" href="fonts.css" type="text/css" /&gt;
          &lt;link href="css/stylesheet.css" rel="stylesheet"&gt;
      &lt;/head&gt;
  
      &lt;body&gt;
          &lt;div class="container"&gt;
              &lt;header&gt;
                  &lt;div class="navbar navbar-inverse"&gt;
                      &lt;div class="navbar-inner"&gt;
                          &lt;div class="container"&gt;
                              &lt;a href="index.php" title="Screening"&gt;&lt;img src="img/blue_logo.png" class="pull-left" title="Screening - Your ticket to your movies" alt="Screening - Your ticket to your movies" /&gt;&lt;/a&gt;
                              &lt;a class="brand" href="index.php"&gt;Screening&lt;/a&gt;
                          &lt;/div&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
              &lt;/header&gt;
              &lt;div id="main" class="well main-content"&gt;
                  &lt;p class="page-title"&gt;"&lt;?php echo $watchlist_name; ?&gt;" Watchlist by &lt;?php echo $first_name; ?&gt; &lt;?php echo $last_name; ?&gt;&lt;/p&gt;
                  &lt;div class="row-fluid"&gt;
                      &lt;section class="span12 watchlist-holder film-list"&gt;
                          &lt;ul class="unstyled"&gt;&lt;?php
                              foreach($films as $key =&gt; $film_item) {
                                  include("watchlist-film-controller.php");?&gt;
                                  &lt;li class="well list-item clearfix"&gt;
                                      &lt;div class="row-fluid"&gt;
                                          &lt;a href="movie.php?id=&lt;?php echo $rt_id; ?&gt;" class="span1 pull-left" title="&lt;?php echo $title; ?&gt;"&gt;&lt;img src="&lt;?php echo $poster_thumb; ?&gt;" alt="&lt;?php echo $title; ?&gt; poster" title="&lt;?php echo $title; ?&gt; poster" /&gt;&lt;/a&gt;
  
                                          &lt;div class="span11 movie-info"&gt;
                                              &lt;p class="search-title"&gt;&lt;a href="movie.php?id=&lt;?php echo $film_item['film_id']; ?&gt;" title="&lt;?php echo $title; ?&gt; (&lt;?php echo $year; ?&gt;)"&gt;&lt;?php echo $title; ?&gt;&lt;/a&gt; &lt;small&gt;(&lt;?php echo $year; ?&gt;)&lt;/small&gt;&lt;/p&gt;&lt;?php
                                              if ($critics_consensus == "") {?&gt;
                                                  &lt;p class="watchlist-synopsis"&gt;No overview available&lt;/p&gt;&lt;?php
                                              } else {?&gt;
                                                  &lt;p class="watchlist-synopsis"&gt;&lt;?php echo $critics_consensus; ?&gt;&lt;/p&gt;&lt;?php
                                              }?&gt;
                                          &lt;/div&gt;
                                      &lt;/div&gt;
                                  &lt;/li&gt;&lt;?php
                              }?&gt;
                          &lt;/ul&gt;
                      &lt;/section&gt;
                  &lt;/div&gt;
                  &lt;p&gt;This Watchlist was generated by &lt;span class="bold"&gt;Screening&lt;/span&gt;.&lt;/p&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/body&gt;
  &lt;/html&gt;&lt;?php
  $html = ob_get_clean();
  $dompdf = new DOMPDF();
  $dompdf-&gt;load_html($html);
  $dompdf-&gt;render();
  $dompdf-&gt;stream("watchlist.pdf");?&gt;
  </code></pre>
  
  <p>Also, if it helps, turning on error reporting gets me the following:</p>
  
  <pre><code>Notice: Undefined variable: submit in \\ICS-FILESHARE\WWW\newmedia.leeds.ac.uk\ug10\cs10aer\screening\watchlist-controller.php on line 20
  Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in \\ICS-FILESHARE\WWW\newmedia.leeds.ac.uk\ug10\cs10aer\screening\watchlist-controller.php on line 107
  Notice: Undefined index: name in \\ICS-FILESHARE\WWW\newmedia.leeds.ac.uk\ug10\cs10aer\screening\watchlist-controller.php on line 111
  Notice: Undefined index: category in \\ICS-FILESHARE\WWW\newmedia.leeds.ac.uk\ug10\cs10aer\screening\watchlist-controller.php on line 112
  Notice: Undefined index: description in \\ICS-FILESHARE\WWW\newmedia.leeds.ac.uk\ug10\cs10aer\screening\watchlist-controller.php on line 113
  Notice: Undefined index: hash in \\ICS-FILESHARE\WWW\newmedia.leeds.ac.uk\ug10\cs10aer\screening\watchlist-controller.php on line 114
  Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in \\ICS-FILESHARE\WWW\newmedia.leeds.ac.uk\ug10\cs10aer\screening\watchlist-controller.php on line 119
  Warning: require_once(//ICS-FILESHARE/WWW/newmedia.leeds.ac.uk/ug10/cs10aer/screening/dompdf/lib/php-font-lib/classes/font.cls.php): failed to open stream: No such file or directory in \\ICS-FILESHARE\WWW\newmedia.leeds.ac.uk\ug10\cs10aer\screening\dompdf\dompdf_config.inc.php on line 335
  Fatal error: require_once(): Failed opening required '//ICS-FILESHARE/WWW/newmedia.leeds.ac.uk/ug10/cs10aer/screening/dompdf/lib/php-font-lib/classes/font.cls.php' (include_path='.;C:\php\pear') in \\ICS-FILESHARE\WWW\newmedia.leeds.ac.uk\ug10\cs10aer\screening\dompdf\dompdf_config.inc.php on line 335
  </code></pre>