fpdf显示奇怪的结果

时间:2016-06-04 03:26:27

标签: javascript php pdf fpdf

我创建了一个按钮。如果我点击按钮,它应该自动下载pdf。

我使用fpdf来制作pdf但不知何故它只是显示加密结果的一些错误。

以下是我的代码

display_table.php

<html>
    <head>
        <script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.12.2.min.js"></script>
        <script src="display_table.js"></script>
    </head>
    <body>
        <input type="button" name="download_pdf" id="download_pdf" value="Download pdf here" onclick="download_pdf()">
    </body>
</html>

display_table.js

function download_pdf() {

        $.ajax({
           type: "POST",
           url: "http://localhost/fpdf/display_table_controller.php",
           data: { download : "download"}, 
           error: function(jqXHR, textStatus, errorThrown) {      
               alert(errorThrown);
            },
           success: function(data)
           {
               alert(data); 
           }
         });
}

display_table_controller.php

<?php
    include("fpdf.php");
    include("courier.php");
    include("helveticab.php");
    $pdf_name = "test.pdf";
    $pdf = new FPDF('P','mm','A4');
    $pdf->AddPage();
    $pdf->SetFont('Arial','B',16);
    $pdf->Cell(40,10,'Hello World!');
    $pdf->Output($pdf_name, "D");
?>

Error message display

有人能告诉我这里有什么不对吗?感谢

1 个答案:

答案 0 :(得分:0)

使用此代码

 <?php
    error_reporting(E_ALL ^ E_DEPRECATED);
    error_reporting(error_reporting() & ~E_NOTICE);
    require('fpdf.php');
    $pdf=new FPDF();
    $pdf->AddPage();
    $pdf->SetFont('Arial','B',10);
    $pdf->Ln();
    $pdf->Ln();

    $pdf->SetFont('times','B',10);
    $pdf->SetTextColor(194,8,8);
    $pdf->Cell(40,7,"Name",1);
    $pdf->Cell(40,7,"Address",1);
    $pdf->Cell(30,7,"Opening Balance ",1);
    $pdf->Cell(40,7,"Account No",1);
    $pdf->Cell(30,7,"IFSCCode",1);

    $pdf->Ln();



           mysql_connect("localhost", "root", "")or die("cannot connect to server"); 
    mysql_select_db("dbname")or die("cannot select DB");
            $sql = "SELECT Bankname,Address,Opbal,AccountNo,IFSCCode FROM tbl_bankmaster";
            $result = mysql_query($sql);

            while($rows=mysql_fetch_array($result))
            {
                $name = $rows[0];
                $address = $rows[1];
                $opbal = $rows[2];
                $account = $rows[3];
                $ifsccode = $rows[4];

                $pdf->SetTextColor(0,0,0);
                $pdf->Cell(40,7,$name,1);
                $pdf->Cell(40,7,$address,1);
                $pdf->Cell(30,7,$opbal,1);
                $pdf->Cell(40,7,$account,1);
                $pdf->Cell(30,7,$ifsccode,1);

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

了解更多http://www.fpdf.org/