首页 文章

生成Pdf时出现PHP FPDF错误

提问于
浏览
0

我正在尝试使用Fpdf生成pdf . 但是在提交按钮时我收到了这个错误 .

致命错误:未捕获的异常“异常”有消息“FPDF错误:一些数据已输出,不能发送PDF文件(输出开始在C:\ XAMPP \ htdocs中\ AutoMall2 \ testindex.php:237)”用C :\ XAMPP \ htdocs中\ AutoMall2 \ FPDF \ fpdf.php:271堆栈跟踪:#0 C:\ XAMPP \ htdocs中\ AutoMall2 \ FPDF \ fpdf.php(1040):FPDF->错误(“某些数据具有.. ')#1 C:\ XAMPP \ htdocs中\ AutoMall2 \ FPDF \ fpdf.php(987):FPDF - > _ checkoutput()#2 C:\ XAMPP \ htdocs中\ AutoMall2 \ testindex.php(274):FPDF->输出('2017-04-0313.pd ...','我')#3 在第271行的C:\ xampp \ htdocs \ AutoMall2 \ fpdf \ fpdf.php中抛出

我已经搜索过这个错误,但没有成功我也看了一些类似的问题但是相同 .

<?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 回答

  • 0

    您正在使用的库中存在问题 . 尝试任何不同或使用dompdf它会对你有所帮助 . https://github.com/dompdf/dompdf

相关问题