php include generated png in pdf via fpdf

喜欢而已 提交于 2019-12-06 06:38:05

You almost had it, you're missing only a couple things. First you need the full server address in the URL for your Image() call, so instead of

$pdf->Image('label.php?imgid=17',0,0,0,0,'PNG');

You need:

$pdf->Image('http://www.yourserver.com/label.php?imgid=17',0,0,0,0,'PNG');

That will eliminate the FPDF error you were encountering. Then to get FPDF to render your output correctly, you need to add a call to AddPage(), so your PDF generation script would become:

require('scpt/fpdf.php');

$pdf = new FPDF('P','in',array(8.5,11));
$pdf->AddPage();
$pdf->Image('http://www.yourserver.com/label.php?imgid=17',0,0,0,0,'PNG');

$pdf->Output('label.pdf','D');

Of course you don't need the SetTextColor(), SetFont(), etc if you're only including the single image. You didn't need the custom class definition either (I removed the unneeded lines).

Don't forget to substitute www.yourserver.com for the appropriate domain and path for your script.

The argument to the Image function needs to be a file, not a URL or another script. Since you already have your label script, the easiest work around would be to download the image to a temp location and then call $pdf->Image() with that temporary file.

This problem occurred With your file name,Make sure your passing file name is valid

function _parsepngstream($f, $file)
{
// Check signature
if($this->_readstream($f,8)!=chr(137).'PNG'.chr(13).chr(10).chr(26).chr(10))
    $this->Error('Not a PNG file: '.$file);

...
}

You need to do only changes that

require('fpdf.php');

and do the

$pdf->Image('http://www.yourserver.com/label.php?imgid=17',0,0,0,0,'PNG');

and run your code...

First, try to check your url with this code

$handle = fopen("http://www.yourserver.com/label.php?imgid=17", "rb");

print_r(fread($handle, 8192));

you with see what the contain in your url

**) make sure your url is not redirect to the login page

Rodolfo Ochoa

much more easy, only put .png in the final of dinamic chain and its all

example:

$pdf->Image('http://www.yourserver.com/label.php?   imgid=17.png',0,0,0,0,'PNG');

or

$pdf->Image('../label.php?imgid=17.png',0,0,0,0,'PNG');

the mime type is not recognized in the url why does not appear png, if it's a stupid mistake but it is proven, google does the same by adding the extension with the url & PNG

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!