And the comments and solutions are:

  1. In lines 2 and 3 there is no need to send the header. FPDF will take care of all.
  2. Before line 11 you should use a SetFont() FPDF method to set the font you wish to use
  3. On lines 24 and 25 you used mysql_query function twice, with errors in syntax
  4. On line 28 you used a nonexisting index 1 (only index 0 exists)
  5. Before line 30 you should again use SetFont() FPDF method (I think)
  6. I do not know where the values $row['id'] and $row['name'] come from. I ignored them. Make sure they exist. (credits also to pzuurveen)
  7. Make sure you can write to the current directory or add a parameter to the Output() method (like 'D' for Download)
  8. I do not know what is the point of line 30. Get rid of it. (credits also to pzuurveen)

The code that works for me is (a bit rearranged to be more clear):

$query = "SELECT name FROM image1 WHERE id=1";
$result = mysql_query($query);

class PDF1 extends FPDF
    // Page header
    function Header()
        // Logo
        $this->Cell(0,10,'UNDER MANAGEMENT QUOTA FOR THE ACADEMIC YEAR 2014-2015',0,0,'C');
        // Line break

$pdf = new PDF1();
// $pdf->Cell(0,10,'id'.$row['id'],0,1);
// $pdf->Cell(0,10,'name'.$row['name'],0,1);
$pdf->Output("image.pdf", 'D');

The code works provided that the image is present and the path to it is correct.

Edited by broj1


Thank you very much zuurveen sir..for your response and the code is working


one question sir.when the image are display in pdf.How to resize that image.


Use the resize parameter of the image function to scale the image . See the documentation.

Something like:

// set the required parameters
$posX = 100;      // position x of the upper left corner 
$posY = 100;      // position y of the upper left corner 
$newWidth = 400;  // new width that you wish to scale to 
$newHeight = 300; // new height that you wish to scale to
$type = '';       // will be kept default
$link = '';       // will be kept default
$align = '';      // will be kept default
$resize = true;   // this will make the image resize

// add the scaled image
$pdf->image($name, $posX, $posY, $newWidth, $newHeight, $type, $link, $align, $resize);

I have this issue a year later apologies for that,
This is my problem a getting an error
Fatal error: Uncaught exception 'Exception' with message 'FPDF error: Image file has no extension and no type was specified: 2' in C:\wamp64\www\testlogin\fpdf\fpdf.php on line 271
( ! ) Exception: FPDF error: Image file has no extension and no type was specified: 2 in C:\wamp64\www\testlogin\fpdf\fpdf.php on line 271

Below is my code kindly assist

$query = ("SELECT * FROM tbl_uploads t where id =2");
$result = mysqli_query($db, $query) ;

$row = mysqli_fetch_row($result);

// Get the image from each row
$url = $row[0];
  // Place the image in the pdf document




Please start your own thread.

From a cursory look, the $url needs to be a url to an image file with an extension like png/gif/jpg/jpeg. However it could also be to a php file that generates an image file.


May be in the wrong order: http://www.fpdf.org/en/doc/output.htm



This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.