CRM Developement
CRM Developement

Reputation: 45

Inserting Image in PDF using FPDF

I want to create PDF using PHP and for this I am using FPDF. Now I want to add two images at top of PDF (one at left corner and one right). I am using following code for this,

Code:-

function Header () {
$this->Image('logo.png',10,20,33,0,'','http://www.fpdf.org/');    
$this->SetFont('Arial', 'B', 20);
$this->SetFillColor(36, 96, 84);
$this->SetTextColor(28,134,238);
$this->Cell(0, 10, "Your Car Comparison Document", 0, 1, 'C', false);
$this->Cell(0, 5, "", 0, 1, 'C', false);
$this->Cell(0, 10, "Thanks for visiting CarConnect.", 0, 1, 'C', false);
$this->Cell(0, 5, "", 0, 1, 'C', false);
}

But when I add image code it will show 404 error on browser else it works properly.

Upvotes: 0

Views: 17554

Answers (4)

ThatMSG
ThatMSG

Reputation: 1506

Make sure that your img path is correct. Your script might lays in a different folder and gets included. In this case make sure you've choosen the right path.

Upvotes: 0

Wasim Khan
Wasim Khan

Reputation: 1237

$pdf->Image('PATH/logo.png',10,3,50);

Upvotes: 0

Carlos Espinoza
Carlos Espinoza

Reputation: 1175

I did the same thing last week. But an annotation:

404 error = page not found; your image or your path probably is wrong.

I used the following code with a image size of 20x10:

$imagenurl = "../imgs/incgaminglabs.png"; // in my case

// 1) left corner in coord x=1 and y=1
$pdf->Cell(0, 0, $pdf->Image($imagenurl, 1,1,20,10), 0, 0, 'C', false,'');

// 2) right corner in coord x=$pdf->GetX() - image width + 1 and y = $pdf->GetY() - image height + 1
$pdf->Cell(0, 0, $pdf->Image($imagenurl, $pdf->GetX()-20+1,$pdf->GetY()-10+1,20,10), 0, 0, 'C', false,'');

I hope it's works for you. Try changing the values.

Upvotes: 1

Girish
Girish

Reputation: 12127

The HTTP url is not looks proper image url, please use correct images url 'http://www.fpdf.org/logo.png' and the Image method params wrong, please see blow

//Image(string file [, float x [, float y [, float w [, float h [, string type [, mixed link]]]]]])


$this->Image('http://www.fpdf.org/logo.png',10,20,33,0); 

Upvotes: 0

Related Questions