我想在我创建的 PDF 文件中插入图像。但是,它根本不会定位。
如果我这样做:
$fpdf->Image($row_products['prod_imagelarge'], 10);
The images will appear however, they're too big.
如果我这样做:
$fpdf->Image($row_products['prod_imagelarge'],30, 40, 40, 40);
Not all images will appear. Only 1 image per page will appear but with the right size.
实际上,我是在 while 循环中插入一张图片。 我想在 pdf 文件中显示的是:(按顺序)
-product name (works fine)
-product image (the problem is here!)
-product description (works fine)
最佳答案
与 Naveed 类似,但对其余的行数据更加完整。诀窍是在放置图像之前捕获 X 和 Y 位置,然后根据新图像手动将横坐标(“位置”)设置到正确的位置。
$image_height = 40;
$image_width = 40;
while ($row_products = mysql_fetch_array($products)) {
$fpdf->Cell(0, 0, $row_products['prod_name'], 0, 2);
$fpdf->Cell(0, 0, $row_products['prod_description'], 0, 2);
// get current X and Y
$start_x = $fpdf->GetX();
$start_y = $fpdf->GetY();
// place image and move cursor to proper place. "+ 5" added for buffer
$fpdf->Image($row_products['prod_imagelarge'], $fpdf->GetX(), $fpdf->GetY() + 5,
$image_height, $image_width)
$fpdf->SetXY($start_x, $start_y + $image_height + 5);
}
关于php - 使用 fpdf 以 PDF 格式显示图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3664525/