title: DOMPDF: Unable to stream pdf: headers already sent
body: <p>I am generating php page using smarty template based on html form input and uploaded files. Using dompdf, I want to save the generated page as a pdf file.</p>
  <p>When the user submits the multipart/form-data, data is posted to itself. Then it undergoes validation process. When all is fine, a new page is generated using a template file. There is no output, instead, dompdf utilizes the template file to stream the pdf file. After solving several stages of problems such as &quot;DOMPDF not found&quot;, insufficient memory etc, I am now stuck with &quot;Unable to stream pdf: headers already sent&quot; error.</p>
  <p>One of the most common problems is presence of line break, white space or any output being before stream() is called. I checked for white space before and after &lt;?php and &gt;?.</p>
  <p>There are nor print_f or echo statements either. How can I troubleshoot this problem? Where does the problem lie...in the smarty template file or the php file itself?
  Here is the code:</p>
  <pre><code>require_once(&quot;dompdf/dompdf_config.inc.php&quot;);
  spl_autoload_register('DOMPDF_autoload');
  $html = $smarty-&gt;fetch('index.tpl');
  $dompdf = new DOMPDF();
  $dompdf-&gt;load_html($html);
  $dompdf-&gt;set_paper('a4', 'portrait');
  $dompdf-&gt;render();
  $dompdf-&gt;stream(&quot;newfile.pdf&quot;);
  </code></pre>