2014-03-14 73 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);