【问题标题】:TCPDF ERROR: Some data has already been output to browser, can't send PDF fileTCPDF 错误:一些数据已经输出到浏览器,不能发送 PDF 文件
【发布时间】:2020-06-21 21:54:49
【问题描述】:

我正在尝试将此“PHP”页面转换为“PDF”页面,但我每次都会收到此消息。虽然,一切看起来都不错。

错误:

-第一个: 注意:未定义的偏移量:0 in \html2pdf\html2pdf.class.php on line 4957

-2end 错误:注意:未定义的偏移量:0 in \html2pdf\html2pdf.class.php on line 4957

-3rd 错误: 警告:无法修改标头信息 - 标头已由 \html2pdf_tcpdf_5.0.002\tcpdf.php 中的(输出开始于 \html2pdf\html2pdf.class.php:4957)发送第6122行

为了清楚起见,我把页面的代码分开了。

我太累了,明天是预科日。请帮忙!

页头:html2pdf的第一部分

<?php ob_start(); ?>

第二行:

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title>Facture</title>
    </head>

身体部位

    <body>
        <?php
        include_once"./html2pdf/html2pdf.class.php";
        include_once"Traitement.php";
        session_start();
        $numcom="";$datecom="";$dateliv="";
        $cur=Traitement::commande($_GET['numcom'],$_SESSION['log']);
        if($cur->rowCount()<>0){
            while($row=$cur->fetch()){
                $numcom=$row[0];
                $datecom=$row[1];
                $dateliv=$row[2];
            }
        }
            $cur->closeCursor();
      ?>
            <div style='margin:0 0 0 0;text-align:left;'>
                <h3 style='margin:1% 0 0 0;display:inline-block'><span style='display:inline-block'>Client: </span><span style='display:inline-block'>".$_SESSION['log']."</span></h3>
                <h3 style='margin:1% 0 0 0'><span style='display:inline-block'>Code de commande: </span><span style='display:inline-block'>".$numcom."</span></h3>
            </div>
            <div style='margin:0 5% 0 0;text-align:left;padding:0 0 0 2%'>
                <h3 style='margin:1% 0 0 0'><span style='display:inline-block'>Date de commande: </span><span style='display:inline-block'>".$datecom."</span></h3>
                <h3 style='margin:1% 0 0 0'><span style='display:inline-block'>Date de livraison: </span><span style='display:inline-'>".$dateliv."</span></h3>
            </div>
        <table style='margin:5% 0 0 0;border:1px solid white'>
            <thead style='background:white;color:black'>
                <th align='center' style=''>Article</th>
                <th align='center' style=''>Quantité</th>
                <th align='center' style=''>Prix unitaire</th>
                <th align='center' style=''>Sous-Total</th>
            </thead>
            <tbody>
                <?php
                $cur=Traitement::achatparcommnde($_GET['numcom'],$_SESSION['log']);
                if($cur->rowCount()<>0){
                    while($row=$cur->fetch()){
                        $nom=$row[0];
                        $prixunitaire=$row[1];
                        $qte=$row[2];
                        $soustotal=$row[1]*$row[2];
                        echo"<td align='center' style=''>$nom</td>
                        <td align='center' style=''>$qte</td>
                        <td align='center' style=''>$prixunitaire Dhs</td>
                        <td align='center' style=''>$soustotal Dhs</td>";
                    }
                }
                    ?>
            </tbody>
            </table>
            <h2 id='foot' align='center' style=''>Merci pour votre achat</h2>
    </body>
</html>

页面底部:html2pdf的第二部分

<?php
$contents=ob_get_clean();
    $pdf=new HTML2PDF("P","A4","fr");
    $pdf->writeHTML($contents);
    $pdf->OutPut("facture.pdf");
?>

【问题讨论】:

    标签: php html2pdf


    【解决方案1】:

    您的“注意:bla bla”错误是给您带来麻烦的错误,因为它们是输出的。事实上,它们不是错误,只是可以忽略的警告。

    通过以下方式禁用 PHP 通知错误:

    error_reporting(E_ALL & ~E_NOTICE);
    

    在 PHP 的开头(你的 html2pdf 模块的 require() 或 include() 之前)。

    【讨论】:

    • 谢谢,错误来自html,如果你看你会得到一个'tr'标签不要添加到表中。
    • 但是,新问题是“ TCPDF ERROR: could not include font definition file: my2font”
    【解决方案2】:

    谢谢,错误出现在 html 部分,如果你对表格很好看,你会得到一个 'tr' 标签,不要添加到。

    【讨论】:

      猜你喜欢
      • 2013-12-07
      • 2013-04-07
      • 1970-01-01
      • 1970-01-01
      • 2012-04-05
      • 2017-01-05
      • 2020-05-15
      • 2017-09-28
      相关资源
      最近更新 更多