简体   繁体   中英

Generating Blank Page FPDF

This is my billingpdf.php, If I click on the submit button it just keeps on generating a blank page. when i tried to remove and put some basic codes on billingpdf.php It works the pdf has been created and it shows the message that i input but when i tried using the submit button it seems that it doesn't generate pdf anymore. Anyone whose expert at FPDF?

<?php
    session_start();
    if (!isset($_SESSION["uemail"])){
        header('Location: login.php');  }
        $uid = $_SESSION['UserID'];
    ?>
    <?php
    if(isset($_POST['submit']))
    {
    require("fpdf.php");
    require ("../util/dbConnection.php");
    $pdf = new FPDF();
    $pdf->AddPage();
    $pdf->SetFont('Arial', '', 10);
    $pdf->Cell(18, 10, '', 0);
    $pdf->Cell(150, 10, 'Testing"', 0);
    $pdf->SetFont('Arial', '', 9);
    $pdf->Cell(50, 10, 'Date: '.date('d-m-Y').'', 0);
    $pdf->Ln(15);
    $pdf->SetFont('Arial', 'B', 11);
    $pdf->Cell(70, 8, '', 0);
    $pdf->Cell(100, 8, 'Billing Assessment', 0);
    $pdf->Ln(23);
    $pdf->SetFont('Arial', 'B', 8);
    $pdf->Cell(20, 8, 'Expense ID', 0);
    $pdf->Cell(30, 8, 'Request Booking', 0);
    $pdf->Cell(20, 8, 'Request Date', 0);
    $pdf->Cell(20, 8, 'Due date', 0);
    $pdf->Cell(25, 8, 'Amount', 0);
    $pdf->Ln(8);
    $pdf->SetFont('Arial', '', 8);
    $sql = "SELECT ExpenseID, reqbookID, RequestBooking, requestDate, amount, 
                             DATE_ADD(requestDate,INTERVAL 30 DAY) as duedate 
                             FROM tblbilling NATURAL JOIN tblbookreq  
                             WHERE UserID = $uid ORDER BY requestDate";
    $result = $conn->query($sql);
    while ($row = $result->fetch_assoc()){
        $pdf->Cell(20, 8, $row['ExpenseID"'], 0);
    $pdf->Cell(30, 8, $row['RequestBooking'], 0);
    $pdf->Cell(20, 8, $row['requestDate'], 0);
    $pdf->Cell(20, 8, $row['duedate'], 0);
    $pdf->Cell(25, 8, $row['amount'], 0);

    }
    $pdf->Output();
    }
    ?>

And this is my billing.php

<h2>Services and Charges</h2>

        <div class="content" style="border:1px dotted black; padding:1%; border-radius:1em; ">  



            <select style="margin-bottom:1%;">
                <option> --- </option>
                <option>Weekly</option>
                <option>Monthly</option>
            </select>
            <select style="margin-bottom:1%;">
                <option> --- </option>
                <option>Laundry</option>
                <option>Cafe</option>
                <option>Maintenance</option>
            </select>

            <input type="text" id="myInput" onkeyup="myFunction()" placeholder="Search for Expenses...">

            <table id="myTable" cellpadding=10>
                <thead>
                    <tr>
                      <th>Expense ID</th>
                      <th>Expense Name</th>
                      <th>Date Requested</th>
                      <th>Date Due</th>
                      <th>Amount</th>
                    </tr>
                </thead>
                <input type="submit" value="Print"style="float:right;" ></input>
                <tbody>
                </form> 
                    <?php 
                        include "../util/dbConnection.php";
                        $sql = "SELECT ExpenseID, reqbookID, RequestBooking, requestDate, amount, DATE_ADD(requestDate,INTERVAL 30 DAY) as duedate FROM tblbilling NATURAL JOIN tblbookreq  WHERE UserID = $uid ORDER BY requestDate";
                        $result = $conn->query($sql);

                        while ($row = $result->fetch_assoc()){
                            echo "<tr>
                            <td>".$row["ExpenseID"]."</td>
                            <td>".$row["RequestBooking"]."</td>
                            <td>".$row["requestDate"]."</td>
                            <td>".$row["duedate"]."</td>
                            <td>".$row["amount"]."</td>
                            </tr>";
                        }
                    ?>

                </tbody>

            </table>


        </div>

Try this, I have same problem to generate dynamic Pdf using FPDF library but that was solved by $pdf->SetAutoPageBreak(false);

        $pdf->AddPage('L','A4');
        $pdf->SetFont('Arial','',8);
        $pdf->SetHeight(4);
        $pdf->SetAutoPageBreak(false);

I have had the same experience several times, and I solved it by the following:

Look at the error_log file in the folder in which you are running your PHP scripts. Frequently, there is an error message at the end of it which relates to the script on which you are getting the error.

In my case, I got this message:

[29-Nov-2019 13:33:44 UTC] PHP Fatal error: Uncaught Exception: FPDF error: Some data has already been output, can't send PDF file (output started at /home/xxxxxx/public_html/sla/connectdb.php:19) in /home/xxxxxx/public_html/sla/fpdf/fpdf.php:271

What it tells me is the classic one about sending HTML statements out before FPDF can produce any part of the report.

It also says that it started in the connectdb.php script at line 19. connectdb.php is a small script that is brought in by an 'include' statement in a main script, and that starts with "<?php" and ends with "?>".

However, beyond that there were two or three carriage returns (CRs), which resulted in blank lines being output as HTML when executing the main script, hence the totally blank page that was displayed. I removed all the CRs, and the report magically worked! Just make sure that there are no places in your scripts which could possibly cause blank lines to be output.

Incidentally, the error log is also very useful in identifying the cause of Error 500 messages which give you no other information to help you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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