dongshuo5101 2014-05-04 13:56
浏览 73
已采纳

使用fpdf将图像显示为pdf时出现致命错误

require_once ('include/fpdf/fpdf17/fpdf.php');
require_once ('include/connection.php');
// require_once('include/fpdf/fpdf17/mem_image.php');

if (isset($_POST['txtid'])) {
    $id = $_POST['txtid'];
    $query = "select * from voter where v_id='$id';";
    $result = mysql_query($query);
    $count = mysql_num_rows($result);
    if ($count == 1) {
            $data = mysql_fetch_array($result);
            $row = mysql_fetch_assoc($result);
            $vid = $data['v_id'];
            $name = $data['name'];
            $surname = $data['surname'];
            $father = $data['father_name'];
            $birth = $data['DOB'];
            $gender = $data['gender'];
            $image = $row['photo'];
            $address = $data['address'];
            $email = $data['email_id'];
            $mobile = $data['mobile'];
            $ward = $data['ward_no'];
            $proof = $data['voter_id_proof'];
            $pdf = new fpdf();
            $pdf->AddPage();
            $pdf->SetFont('Times', '', 15);
            $pdf->Cell(20, 10, 'Voter ID: ');
            $pdf->Setx(50);
            $pdf->Cell(20, 10, $vid, 0, 1);
            $pdf->Cell(13, 10, 'Name: ');
            $pdf->Setx(50);
            $pdf->Cell(20, 10, $name, 0, 1);
            $pdf->Cell(10, 10, 'Surname: ');
            $pdf->Setx(50);
            $pdf->Cell(20, 10, $surname, 0, 1);
            $pdf->Cell(20, 10, 'Father Name: ');
            $pdf->Setx(50);
            $pdf->Cell(20, 10, $father, 0, 1);
            $pdf->Cell(20, 10, 'Date of Birth: ');
            $pdf->Setx(50);
            $pdf->Cell(20, 10, $birth, 0, 1);
            $pdf->Cell(20, 10, 'Gender: ');
            $pdf->Setx(50);
            $pdf->Cell(20, 10, $gender, 0, 1);
            $pdf->Cell(20, 5, 'Photo: ');
            $pdf->Setx(50);
            $pdf->MemImage($image, 50, 30, 40);
            $pdf->cell(20, 10, 'address: ');
            $pdf->Setx(50);
            $pdf->Cell(20, 10, $address, 0, 1);
            $pdf->Cell(20, 10, 'Email ID: ');
            $pdf->Setx(50);
            $pdf->Cell(20, 10, $email, 0, 1);
            $pdf->Cell(20, 10, 'Mobile NO.: ');
            $pdf->Setx(50);
            $pdf->Cell(20, 10, $mobile, 0, 1);
            $pdf->Cell(20, 10, 'Ward NO.: ');
            $pdf->Setx(50);
            $pdf->cell(20, 10, $ward, 0, 1);
            $pdf->cell(20, 10, 'ID Proof');
            $pdf->Setx(50);
            $pdf->cell(20, 10, $proof, 0, 1);

            $pdf->Output();
    }
    else {
            echo "<script language='javascript'>";
            echo "alert('Please Enter Your Valid Voter Id');";
            echo "</script>";
    }
}
?>

This code show this error:

Fatal error: 
Call to undefined method FPDF::MemImage() in C:\wamp\www\Election Portal\generate_pdf.php on line 50
  • 写回答

1条回答 默认 最新

  • dongliqin6939 2014-06-03 09:09
    关注

    From the example given on the documentation, you need to require the mem_image add-on (the line you commented out at the top). As the add-on extends the FPDF class you need to instantiate the subclass, so change

    $pdf = new fpdf();
    

    to

    $pdf=new MEM_IMAGE();
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 求大家看看Nonce如何配置
  • ¥15 Matlab怎么求解含参的二重积分?
  • ¥15 苹果手机突然连不上wifi了?
  • ¥15 cgictest.cgi文件无法访问
  • ¥20 删除和修改功能无法调用
  • ¥15 kafka topic 所有分副本数修改
  • ¥15 小程序中fit格式等运动数据文件怎样实现可视化?(包含心率信息))
  • ¥15 如何利用mmdetection3d中的get_flops.py文件计算fcos3d方法的flops?
  • ¥40 串口调试助手打开串口后,keil5的代码就停止了
  • ¥15 电脑最近经常蓝屏,求大家看看哪的问题