簡體   English   中英

TCPDF ERROR: Some data has been output to browser, can't send PDF file

[英]TCPDF ERROR: Some data has already been output to browser, can't send PDF file

我正在嘗試將此“PHP”頁面轉換為“PDF”頁面,但我每次都會收到此消息。 雖然,一切看起來都不錯。

錯誤:

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

-2end 錯誤:注意:未定義的偏移量:0 in \html2pdf\html2pdf.class.php 在第 4957 行

-3rd error: Warning: Cannot modify header information - headers already sent by (output started at \html2pdf\html2pdf.class.php:4957) in \html2pdf_tcpdf_5.0.002\tcpdf.php on line 6122

我將頁面代碼分開以使其清楚。

我太累了,明天是預科日。 請幫忙 !

頁首:html2pdf的第一部分

<?php ob_start(); ?>

2端線:

<!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");
?>

您的“注意:bla bla”錯誤是給您帶來麻煩的錯誤,因為它們是 output。 事實上,它們不是錯誤,只是可以忽略的警告。

禁用 PHP 注意錯誤:

error_reporting(E_ALL & ~E_NOTICE);

在 PHP 的開頭(您的 html2pdf 模塊的 require() 或 include() 之前)。

謝謝,錯誤出現在 html 部分,如果你對表格看起來很好,你會得到一個不要添加的“tr”標簽。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM