繁体   English   中英

FPDF 错误:部分数据已经输出。 无法发送 PDF 文件

[英]FPDF error: some data has already been output. Can't send PDF file

我正在使用 FPDF 库生成 PDF 文档,但出现错误“某些数据已输出,无法发送 PDF”

<?php
function fetch_data()
{
    //užklausa
    include('database_connection.php');
    $query = "SELECT * FROM mvap.daiktas";
    $statement = $connect->prepare($query);
    $statement->execute();
    $result = $statement->fetchAll();
    $id = 1;
    foreach($result as $row)
    {
        $pavadinimas = $row['daiktoPavadinimas'];
        $inventorinis = $row['inventorinisNr'];
    }
    $data = '2020-01-25';
    $html = '
    <body>
        <style>
            th {font-weight: bold; font-family:  };
            tr {font-weight: normal};
        </style>
        <table border="1" cellpadding="4" cellspacing="0" style="text-align: center">
            <tr>
                <th width="30px" height="5">Eil. Nr.</th>
                <th width="130px" height="5">Materialinės vertybės pavadinimas</th>
                <th width="80px" height="5">Inventorinis numeris</th>
                <th width="100px" height="5">Gamyklinis numeris</th>
                <th width="70" height="5">Gavimo data</th>
                <th width="65" height="5">Gavėjo parašas</th>
                <th width="70" height="5">Grąžinimo data</th>
                <th width="80" height="5">Grąžinančio asmens parašas</th>
                <th width="70" height="5">Priimančio asmens parašas</th>
                <th width="80" height="5">Pastabos</th>
            </tr>
            <tr>
                <td>'. $id .'</td>
                <td>'. $pavadinimas .'</td>
                <td>'. $inventorinis .'</td>
                <td>-</td>
                <td>'. $data .'</td>
                <td>-</td>
                <td>-</td>
                <td>-</td>
                <td>-</td>
                <td>-</td>
            </tr>

        </table>
    </body>

    ';
    return $html;
}
if(isset($_POST['submit1']))
{
    require('libs/TCPDF/tcpdf_import.php');
    $obj_pdf = new TCPDF('L', PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
    $obj_pdf->SetCreator(PDF_CREATOR);
    $obj_pdf->SetTitle("Apskaitos kortelė");
    $obj_pdf->SetHeaderData('', '', PDF_HEADER_TITLE, PDF_HEADER_STRING);
    $obj_pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
    $obj_pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
    $obj_pdf->SetDefaultMonospacedFont('dejavuserif');
    $obj_pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
    $obj_pdf->SetMargins(PDF_MARGIN_LEFT, '10', PDF_MARGIN_RIGHT);
    $obj_pdf->setPrintHeader(false);
    $obj_pdf->setPrintFooter(false);
    $obj_pdf->SetAutoPageBreak(TRUE, 10);
    $obj_pdf->SetFont('dejavuserif', '', 10);
    $obj_pdf->AddPage();
    $obj_pdf->Cell(0,6,'ĮMONĖ',0,0,'C');
    $obj_pdf->Ln();
    $obj_pdf->SetLineWidth(0.5);
    $obj_pdf->Line(5, 15, 297-5, 15);
    $obj_pdf->Ln();
    $obj_pdf->SetFontSize(12);
    $obj_pdf->Cell(0,20,'KOMPIUTERINĖS TECHNIKOS, RYŠIO PRIEMONIŲ IR PROGRAMINĖS ĮRANGOS APSKAITOS KORTELĖ',0,0,'C');
    $obj_pdf->Ln();
    $obj_pdf->SetFontSize(10);
    $obj_pdf->Cell(20, 40, 'Valdybos, skyriaus pavadinimas' , 0, false, 'L', 0, '', 0, false, 'T', 'M');
    $obj_pdf->Cell(230, 40, 'SKOV NKC', 0, false, 'C', 0, '', 0, false, 'T', 'M');
    $obj_pdf->Line(10, 65, 297-100, 65);
    $obj_pdf->Ln(0);
    $obj_pdf->Cell(20, 55, 'Turto buvimo vieta, kab. Nr.' , 0, false, 'L', 0, '', 0, false, 'T', 'M');
    $obj_pdf->Cell(230, 55, 'Kabinetas', 0, false, 'C', 0, '', 0, false, 'T', 'M');
    $obj_pdf->Line(10, 72, 297-100, 72);
    $obj_pdf->Ln(0);
    $obj_pdf->Cell(20, 70, 'Atsakingo žmogaus vardas, pavardė' , 0, false, 'L', 0, '', 0, false, 'T', 'M');
    $obj_pdf->Cell(230, 70, 'Vardenis Pavardenis', 0, false, 'C', 0, '', 0, false, 'T', 'M');
    $obj_pdf->Line(10, 80, 297-100, 80);
    $content = '';
    $content .= fetch_data();
    $obj_pdf->SetXY(5, 90);
    $obj_pdf->writeHTML($content);
    $obj_pdf->Output('doc.pdf', 'I');
}
?>

我试图在开始时添加“ob_start()”,在最后添加 ob_end_flush()” 我知道这不是这个问题的第一个话题,但试图在这个论坛中找到信息,现在我不知道该怎么做。 我希望有人可以帮助我解决这个问题。

解决了我的问题。 我不会删除我的主题。 希望这会对某人有所帮助。 通过将此 php 代码发布到另一个空白 php 文件并从另一个文件按钮单击调用该文件来解决问题。 现在它可以正常工作了。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM