ano*_*123 6 php pdf image fpdf
我想在我创建的PDF文件中插入图像.但是,它根本不会很好地定位.
如果我这样做:
$fpdf->Image($row_products['prod_imagelarge'], 10);
Run Code Online (Sandbox Code Playgroud)
然而,图像会出现,它们太大了.
如果我这样做:
$fpdf->Image($row_products['prod_imagelarge'],30, 40, 40, 40);
Run Code Online (Sandbox Code Playgroud)
并非所有图像都会出现.每页只显示1张图片,但尺寸合适.
实际上,我在while循环中插入一个图像.我希望在pdf文件中显示的是:(按顺序)
-product name (works fine)
-product image (the problem is here!)
-product description (works fine)
Run Code Online (Sandbox Code Playgroud)
与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);
}
Run Code Online (Sandbox Code Playgroud)
如果一个页面包含许多图像,则可能是您的图像彼此放置.您应该在一个页面上更改每个图像的位置.尝试这样的事情.
for( $i=10; $i<=200; $i=$i+10 ) {
$fpdf->Image($row_products['prod_imagelarge'],30, $i, 40, 40);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
28425 次 |
| 最近记录: |