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 如何在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,如何解決?
  • ¥15 c++头文件不能识别CDialog