使用fpdf以PDF显示图像 [英] Display image in PDF using fpdf

查看:102
本文介绍了使用fpdf以PDF显示图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在创建的PDF文件中插入图像.但是,它的位置根本不好.

I want to insert an image in my created PDF file. However, it won't position well at all.

如果我这样做:

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

并非所有图像都会出现.每页只会显示1张图片,但 合适的尺寸.

Not all images will appear. Only 1 image per page will appear but with the right size.

实际上,我正在将图像插入while循环内. 我想在pdf文件中显示的是:(按顺序)

Actually, I am inserting an image inside a while loop. What I would want to display in the pdf file is: (in order)

-product name (works fine)  
-product image (the problem is here!)  
-product description (works fine)

推荐答案

与Naveed类似,但其余的行数据则更加完整.技巧是在放置图像之前捕获X和Y位置,然后在给定新图像的情况下将横坐标(位置")手动设置到适当的位置.

Similar to Naveed, but a little more complete with the rest of your row data. The trick is to capture the X and Y position before placing the image and then manually set the abscissa ("position") to the proper place, given the new image.

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

这篇关于使用fpdf以PDF显示图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆