php - 使用 fpdf 以 PDF 格式显示图像

标签 php image pdf fpdf

我想在我创建的 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/

相关文章:

image - 每当未成功创建缩略图时,强制 ffmpeg 以错误代码退出

css - 更改流体图像纵横比 css

c# - 如何在 .net 中将 html 内容写入 pdf

macos - 在 Mac OS X 上使用 Doxygen 创建 PDF

macos - 将 SwiftUI 应用程序中的顶部栏菜单项映射到打开特定的捆绑 PDF?

php - 在 php 中,我想将 s3 文件下载到浏览器而不将其存储在我的服务器上

php - SQL 查询在 PHP 中不起作用

php - 访问paypal支付时http响应码500

PHP 和 Netbeans - 使用 sftp 或 svn 获取远程资源

ios - Swift iOS 中的屏幕截图?