Question

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
Was it helpful?

Solution

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();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top