doutu6658 2017-04-03 11:28
浏览 189

生成Pdf时出现PHP FPDF错误

I am trying to generate pdf using Fpdf. But i got this error while submitting the button.

Fatal error: Uncaught exception 'Exception' with message 'FPDF error: Some data has already been output, can't send PDF file (output started at C:\xampp\htdocs\AutoMall2\testindex.php:237)' in C:\xampp\htdocs\AutoMall2\fpdf\fpdf.php:271 Stack trace: #0 C:\xampp\htdocs\AutoMall2\fpdf\fpdf.php(1040): FPDF->Error('Some data has a...') #1 C:\xampp\htdocs\AutoMall2\fpdf\fpdf.php(987): FPDF->_checkoutput() #2 C:\xampp\htdocs\AutoMall2\testindex.php(274): FPDF->Output('2017-04-0313.pd...', 'I') #3 {main} thrown in C:\xampp\htdocs\AutoMall2\fpdf\fpdf.php on line 271

I already search for this error but no success I also look some similar question but same.

<?php 
include_once('connect.php');
date_default_timezone_set("Asia/Karachi");
$date=date("Y-m-d");
$time=date("h:i:s A");
?>
<!DOCTYPE html>
<html>
<head>
    <title>Car Parking System</title>
    <link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">
    <link rel="stylesheet" href="css/bootstrap-theme.css"/>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <script src="js/bootstrap.min.js" type="text/javascript"></script>
</head>

<style type="text/css">
    body{
        background: #222222;
    }
    label{
        color: white;
        font-size: 1.4em;
        text-transform: uppercase;
        font-family: 'gatepassfont';
        font-weight: 600;
    }
    .heading
    {
        color:white;
    }

    table tr td
    {
        padding: 50px;
    }
    .custom_button
    {
        background:red;
        color:white;
        padding:4px 20px 4px 20px;
        font-weight: 50px;
        font-size: 24px;
        /*margin:0px 0px 0px 115px;*/
    }
    .custom_button:hover
    {
        background:#b30000;
        color:white;
    }

    .select_text
    {
        border-radius: 0px;
        background:#4d4d4d;
        color:white;

        border-style: none;
        font-size: 1.2em;
        text-transform: uppercase;
        font-family: 'gatepassfont';
        font-weight: 100;
    }

    .textbox_color
    {
        background:#4d4d4d;
        color:white;
        border-style: none;
        border-radius:0px;
        font-family: 'gatepassfont';
        font-size: 1.2em;
        /*text-transform: uppercase;*/
        font-weight: 100;
    }
    @font-face {
        font-family: 'gatepassfont';
        src: url('BebasNeue-webfont.woff') format('woff');/* Super Modern Browsers */
    }

    h2.gatepass
    {
        /*border-bottom:solid 5px #fa565a;*/
        padding-top: 5px; 
        padding-bottom: 5px; 
        font-family: 'gatepassfont';
        font-size: 2em;
        background:#ed1c24 ;

        font-weight: 300;
        padding-right: -200px;


    }

    .logo
    {
        width:250px;
        height:auto;
        padding: 10px;
    }
    .slogan
    {
        color:white;
        font-size: 0.5em;
        font-style: italic;
        position: relative;
        top:33px;
        left: -130px;
    }

</style>


<script type="text/javascript" src="tableExport/jquery.js"></script>
<script type="text/javascript" src="tableExport/tableExport.js"></script>
<script type="text/javascript" src="tableExport/jquery.base64.js"></script>
<script type="text/javascript" src="tableExport/html2canvas.js"></script>

<script type="text/javascript" src="tableExport/jspdf/jspdf.js"></script>
<script type="text/javascript" src="tableExport/jspdf/libs/base64.js"></script>
<script type="text/javascript" src="tableExport/jspdf/libs/sprintf.js"></script>
<script type="text/javascript">

</script>

<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.0.272/jspdf.debug.js"></script>
<script type="text/javascript" src="jsPDFautotable/jspdf.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf-autotable/2.3.0/jspdf.plugin.autotable.js"></script>
<!--Sweet Alert-->

<link rel="stylesheet" type="text/css" href="sweetalert2/dist/sweetalert2.min.css">
<script src="sweetalert2/dist/sweetalert2.min.js"></script>
<body>



    <div class="container">

        <!--form horizontal-->
        <div class="row">   
            <div class="container">

                <img src="automalllogo.png" class="img-responsive col-lg-4 col-md-4 col-sm-12 col-xs-12 col-lg-offset-4 col-md-offset-4 logo" />
                <p class="slogan">Pleasure of Extreme Machines</p>
                <h2 class="heading gatepass text-center col-lg-4 col-md-4 col-sm-12 col-xs-12 col-lg-offset-4 col-md-offset-4"><strong>GATE PASS</strong></h2>

            </div> 
        </div> 
        <!--form-->
        <form method="POST" action="">

            <div class="form-group col-lg-4 col-md-4 col-lg-offset-4 col-md-offset-4" >
                <label class="control-label " >VEHICLE</label>
                <div  >          
                    <select name="vehicle" class="form-control select_text">


                        <option value="Toyota" >Toyota</option>
                        <option value="Civic">Civic</option>


                    </select>
                </div>
            </div>

            <div class="form-group col-lg-4 col-md-4 col-lg-offset-4 col-md-offset-4  ">
                <label  >REG/CH.NO</label>

                <div >          
                    <input type="text" name="registration" class="form-control textbox_color"  placeholder="Enter Registration No" required="">
                </div>
            </div>
            <div class="form-group col-lg-4 col-md-4 col-lg-offset-4 col-md-offset-4 ">
                <label class="control-label " >MILEAGE</label>
                <div >          
                    <input type="text" name="mileage" class="form-control textbox_color"  placeholder="Enter Mileage" required="">
                </div>
            </div>

            <div class="form-group col-lg-4 col-md-4 col-lg-offset-4 col-md-offset-4 ">
                <label class="control-label " >TO</label>
                <div >          
                    <input type="text" name="to" class="form-control textbox_color"  placeholder="Enter To" required="">
                </div>
            </div>

            <div class="form-group col-lg-4 col-md-4 col-lg-offset-4 col-md-offset-4 ">
                <label class="control-label " >DRIVER</label>
                <div >          
                    <input type="text" name="driver" class="form-control textbox_color"  placeholder="Enter driver" required="">
                </div>
            </div>

            <div class="form-group col-lg-4 col-md-4 col-lg-offset-4 col-md-offset-4">
                <label class="control-label " >C/O:</label>
                <div >          
                    <input type="text" name="co" class="form-control textbox_color"  placeholder="Enter C/O" required="">
                </div>
            </div>

            <div class="form-group col-lg-4 col-md-4 col-lg-offset-4 col-md-offset-4 " >
                <label class="control-label " >APPROVED BY</label>
                <div  >          
                    <select name="approvedby" class="form-control select_text">


                        <option value="Irfan">Irfan</option>
                        <option value="Rizwan">Rizwan</option>


                    </select>
                </div>
            </div>


            <div class="form-group col-lg-8 col-md-8 col-lg-offset-4 col-md-offset-4">        
                <div >
                    <button type="submit" name="submit" class="btn custom_button" id="submit">Submit</button>

                </div>
            </div>
        </form>
        <!--form-->

    </div>
    <!--end-->






</body>
</html>

<?php


if(isset($_POST['submit']))
{
    $vehicle=$_POST['vehicle'];
    $registration=$_POST['registration'];
    $mileage=$_POST['mileage'];
    $to=$_POST['to'];
    $driver=$_POST['driver'];
    $co=$_POST['co'];
    $approvedby=$_POST['approvedby'];
    $date;
    $time;



    $query="INSERT INTO gatepass (vehicle,registration,mileage,to_location,driver,co,approvedby,currentdate,currenttime) VALUES ('$vehicle','$registration','$mileage','$to','$driver','$co','$approvedby','$date','$time')";
    $queryrun=mysqli_query($connection,$query);



    $connection=mysqli_connect($localhost,$username,$password,$db);
    $query="SELECT id from gatepass WHERE currentdate='$date' AND currenttime='$time'";

    $queryrun=mysqli_query($connection,$query);


    $row=mysqli_fetch_array($queryrun);
    $ID=$row['id'];
    if($queryrun==TRUE)
    {
        require('fpdf/fpdf.php');
        $pdf = new FPDF();
        $pdf->AddPage();
        $pdf->SetFont('Arial','B',16);
        $pdf->Cell(40,10,'working or not?!');
        $pdf->Output($date.$ID.'.pdf','I'); 


    }
    else{
        mysqli_error($connection);
    }
}
?>

enter image description here

  • 写回答

1条回答 默认 最新

  • douzhi1972 2017-04-03 11:52
    关注

    There is problem in your library which you are using. try any different or use dompdf it will be helpful for you. https://github.com/dompdf/dompdf

    评论

报告相同问题?

悬赏问题

  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?