dtjwov4984 2016-06-04 03:26
浏览 21

fpdf显示奇怪的结果

I had created a button. If i click the button it should automatically download a pdf.

I used fpdf to make the pdf but somehow it just show me some error with encrypted result.

Below is my code

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

Can someone tell me what wrong here? thanks

  • 写回答

1条回答 默认 最新

  • dpbl91234 2016-06-04 04:50
    关注

    use this code

     <?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();
        ?>
    

    learn more to http://www.fpdf.org/

    评论

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?