title: dompdf error Unable to stream pdf: headers already sent
body: <p>My case is a little bit more complicated than the others answered before. with the same code the results are different.</p>
  
  <p><strong>WORKING CENARIO - 1st step</strong></p>
  
  <p>Go to <a href="http://renamchristofoletti.com/en/works/covers/" rel="nofollow">http://renamchristofoletti.com/en/works/covers/</a></p>
  
  <p>Click on Thumbnails, and ADD TILL 4 images.</p>
  
  <p>Click on Download, and than, Download Portfolio.</p>
  
  <p>PDF was generated as expected. =)</p>
  
  <p><strong>ERROR CENARIO - 2nd step</strong></p>
  
  <p>Do the same thing as above, but now, add more than 6 images in the Thumbnails.</p>
  
  <p>PDF get a "Unable to stream pdf: headers already sent error"</p>
  
  <p>Doesn't matter with image are you selecting, same thing happens.</p>
  
  <p><strong>DOMPDF CODE</strong></p>
  
  <pre><code>ob_clean();
  echo '&lt;html&gt;&lt;body&gt;...'; // above html and css goes here
  
  $images2 = str_replace(' ', "", $_COOKIE['rc_folio']);
  $images = explode(',', $images2);
  $images = array_filter($images);
  
  foreach ( $images as $image ) {
      $img_id = get_image_id($image);
  
      $imglocal = wp_get_attachment_metadata( $img_id );
  
          $img_abs_path = ABSPATH . 'wp-content/uploads/' . $imglocal['file'];
          list($width, $height) = getimagesize($img_abs_path);
          if ($width &gt; $height) {
              // Landscape
              echo '&lt;div style="page-break-after: always; text-align: center;"&gt;&lt;div class="content-line"&gt;&lt;/div&gt;&lt;div class="content-line-2"&gt;&lt;/div&gt;&lt;img src="' . $img_abs_path . '" style="width: 80%; max-width: 80%; height: auto; margin-top: 250px;" /&gt;&lt;/div&gt;'; 
          } else {
              // Portrait or Square
              echo '&lt;div style="page-break-after: always; text-align: center;"&gt;&lt;div class="content-line"&gt;&lt;/div&gt;&lt;div class="content-line-2"&gt;&lt;/div&gt;&lt;img src="' . $img_abs_path . '" style="width: auto; height: 60%; max-height: 60%; margin-top: 180px;" /&gt;&lt;/div&gt;';
          }
  }
  echo '&lt;/body&gt;&lt;/html&gt;';
  
  $html = ob_get_contents();
  ob_get_clean();
  
  $pdf_path = ABSPATH . 'wp-content/themes/moqueca/dompdf-master/dompdf_config.inc.php';
  require_once( $pdf_path );
  
  $dompdf = new DOMPDF();
  $dompdf-&gt;load_html($html);
  $dompdf-&gt;set_paper('letter', 'portrait');
  $dompdf-&gt;render();
  $dompdf-&gt;stream("renam_christofoletti_customfolio.pdf");
  exit();
  </code></pre>
  
  <p>Please can anyone clarify my mind about this? I've tried many other solutions, but nothing seens to work.</p>
  
  <p>Thanks in advance!</p>