当我尝试使用html2pdf lib打印PDF时出现错误:
致命错误:未捕获的异常:TCPDF错误:已经输出了一些数据,无法在C:\ xampp \ htdocs \ Work \ AppDarbNajah \ lib \ vendor \ tecnickcom \ tcpdf \ tcpdf.php:php中发送PDF文件堆栈跟踪:#0 C:\ xampp \ htdocs \ Work \ AppDarbNajah \ lib \ vendor \ tecnickcom \ tcpdf \ tcpdf.php(7621):TCPDF-> Error('Some data has a ......')#1 C: \ xampp \ htdocs \ Work \ AppDarbNajah \ lib \ vendor \ spipu \ html2pdf \ src \ Html2Pdf.php(575):TCPDF-> Output('document.pdf','I')#2 C:\ xampp \ htdocs \ Work \ AppDarbNajah \ App \ Controller \ ArticleController.php(41):Spipu \ Html2Pdf \ Html2Pdf-> output()#3 C:\ xampp \ htdocs \ Work \ AppDarbNajah \ Public \ index.php(46):App \ Controller \ ArticleController-> printlest()#4 {main}在2926行上的C:\ xampp \ htdocs \ Work \ AppDarbNajah \ lib \ vendor \ tecnickcom \ tcpdf \ tcpdf.php中抛出
use Spipu\Html2Pdf\Html2Pdf;
public function printlest(){
//echo 'print';
require_once ROOT.'/lib/vendor/autoload.php';
$pdf = new Html2Pdf('P', 'A4', 'en');
$pdf->writeHTML('fffff');
$pdf->output();
}
答案 0 :(得分:2)
您最有可能遇到此错误,因为输出缓冲已经开始。
您可以在调用output()
函数之前干净地结束输出缓冲区,这应该为您解决:
$pdf = new Html2Pdf('P', 'A4', 'en');
$pdf->writeHTML('fffff');
ob_end_clean();
$pdf->output();