2014-03-14 32 views
0

我想使用PHP創建PDF,爲此我使用FPDF。現在我想在PDF頂部添加兩個圖像(左上角和右側一個)。我使用如下代碼爲此,使用FPDF在PDF中插入圖像

代碼: -

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); 
} 

但是當我添加圖像的代碼,它會顯示瀏覽器的其他404錯誤它工作正常。

回答

0

的HTTP URL不是看起來正確的圖像URL,請使用正確的圖像URL 'http://www.fpdf.org/logo.png'Image方法PARAMS錯了,請參閱打擊

//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); 
0

製作舒爾你的IMG路徑是正確的。您的腳本可能會放置在其他文件夾中幷包含在其中。在這種情況下,請確保你選擇了正確的道路。

+0

在同一個文件夾中有一個圖像(logo.png)我也把圖像的完整url,但我面臨同樣的問題。 –

1

上週我做了同樣的事情。但註釋:

404 error = page not found;你的形象或你的道路可能是錯誤的。

我用下面的代碼用20×10的圖像尺寸:

$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,''); 

我希望這是對你的作品。嘗試更改值。

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