繁体   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