簡體   English   中英

FPDF/PHP - 如何使用 FPDF 在 php 中生成 pdf 文件?

[英]FPDF/PHP - How to generate a pdf file in php using FPDF?

我正在嘗試使用 fpdf 在 php 代碼中生成 pdf 文件。 但是,當我在項目中運行此代碼時,這是我得到的輸出:FPDF error: Some data has been output, can't send PDF file (output started at C:\\xampp\\htdocs\\header.php: 92)。 header.php 不是編寫此腳本的文件。 我嘗試使用 ob_clean(); 和 ob_end_flush();。 但它不起作用。

 <?php

    require("fpdf/fpdf.php");
    $pdf = new FPDF();
    global $DB;
    $orderID=$_REQUEST['garID'];
    $sql = "SELECT * FROM `" . $DB->pre . "garorder` WHERE garID= '" . $orderID . "'"; 
    $d = $DB->dbRow($sql);
    echo 'name:'.$d['orderdate'].' Party Code :'.$d['partyCode'];

    $pdf->AddPage();

            $pdf->Rect(5, 5, 200, 287, 'D');


             $pdf->Cell(10);
             $pdf->SetFont("Arial","B","8");
             $pdf->SetXY (10,30);
             $pdf->MultiCell(50,5,"  ",1,1);

    $pdf->Ln(); 

          $pdf->SetFont('helvetica','B',10);
          $pdf->Cell(190,7,'Order Details',1,2,'C');
          $pdf->SetFont('helvetica','',10);
          $y= $pdf->GetY();
          $pdf->MultiCell(95,8, "Garment ID: "."\nParty Code: "."\nOrder Date: " , 'LRB',1 );
          //$x= $pdf->GetX();
          //$pdf->setXY($x+95,$y);
          $pdf->Cell(90);
          $pdf->SetFont('helvetica','',10);
         $pdf->SetXY (105,62);
          $pdf->MultiCell(95,12, "Name: "."\nDelivery Status: " , 'LRB',1 );
      $pdf-> Ln();
         $pdf->Cell(32,10,'Material Description',1,0,'L',0);
         $period = 50;
         for($x=36;$x <=$period; $x=$x+2){

           $pdf->Cell(20,10,$x,1,0,'L',0);  



         }


    $pdf->Output();


    ?>

消除

 echo 'name:'.$d['orderdate'].' Party Code :'.$d['partyCode'];

那將修復它。

或添加ob_start(); ob_end_flush(); 在開頭和結尾分別是這樣的:

<?php
ob_start();
require('fpdf.php');
$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Cell(40,10,'Hello World!');
$pdf->Output();
ob_end_flush(); 
?>

這里有幾個很好的例子FPDF 錯誤:一些數據已經輸出,無法發送 PDF

暫無
暫無

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

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