DOMPDF:无法流pdf:标头已发送
这个问题在各个论坛上已经提出了数百次;有些已经解决,有些还没有.我检查了很多资源,但是无法解决我的问题.我正在使用基于html表单输入和上传文件的smarty模板生成php页面.使用dompdf,我想将生成的页面另存为pdf文件.当用户提交多部分/表单数据时,数据将发布到其自身.然后,它进行验证过程.一切正常后,将使用模板文件生成一个新页面.没有输出,而是dompdf使用模板文件流式传输pdf文件.解决了多个阶段的问题后,例如找不到DOMPDF",内存不足等,我现在陷入了无法流pdf:标头已发送"错误.最常见的问题之一是换行,空白或在stream()调用之前出现的任何输出.我在?之前和之后检查了空格.也没有print_f或echo语句.如何解决此问题?问题出在哪里……是smarty模板文件还是php文件本身? 这是代码:
This question has been raised hundred of times in various fora; some have been solved, some not. I checked plenty of resources, but my issue could not be resolved. 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. 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 "DOMPDF not found", insufficient memory etc, I am now stuck with "Unable to stream pdf: headers already sent" error. 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 ?. 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:
require_once("dompdf/dompdf_config.inc.php");
spl_autoload_register('DOMPDF_autoload');
$html = $smarty->fetch('index.tpl');
$dompdf = new DOMPDF();
$dompdf->load_html($html);
$dompdf->set_paper('a4', 'portrait');
$dompdf->render();
$dompdf->stream("newfile.pdf");
简单解决方案:
在流之前写在下面的行中,它将显示确切的新行或空格即将到来的地方
write below lines before stream, it will show where exactly new line or space is coming
$f;
$l;
if(headers_sent($f,$l))
{
echo $f,'<br/>',$l,'<br/>';
die('now detect line');
}