用PHP和FPDF插入图像 [英] Inserting an image with PHP and FPDF

查看:110
本文介绍了用PHP和FPDF插入图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试插入图像,但不想指定x和y坐标.有可能吗?

I'm trying to insert an image but do not want to specify the x and y coordinates. Is that possible?

$pdf->Image($image1, 5, 70, 33.78);

我希望能够指定大小(33.78),但不能指定x和y,以便它根据内容移动.

I want to be able to specify the size (33.78) but not the x and y so that it moves based on the content.

$pdf->Write( 70, $reportTitle );
$pdf->Ln( 45 );
$pdf->SetFont( 'Arial', '', 12 );
$pdf->Write( 6, $reportSubtitle );

/**
  Create product 1
**/
$pdf->Ln( 10 );
$pdf->SetFont( 'Arial', '', 12 );
$pdf->Write( 6, $prod1title );
$pdf->Ln( 30 );
$pdf->SetFont( 'Arial', '', 10 );
$pdf->Write( 5, $prod1sub );
$pdf->Ln( 30 );
$pdf->Image($image1, 5, 70, 33.78);

以上是我使用的代码.如果$ reportSubtitle为两行或三行,则会向下推$ prod1title和$$ prod1sub,并且不可避免地将其推到固定的图像下方.

The above is the code I use. If $reportSubtitle is two or three lines, it pushes $prod1title and $$prod1sub down, and inevitably under the image that is fixed. Is there no way to have the image act like the product title and subtitle and be pushed down too while still declaring the size?

推荐答案

我知道了,实际上很简单.

I figured it out, and it's actually pretty straight forward.

设置变量:

$image1 = "img/products/image1.jpg";

然后创建一个单元格,放置它,然后设置图像,而不是设置图像的位置,

Then ceate a cell, position it, then rather than setting where the image is, use the variable you created above with the following:

$this->Cell( 40, 40, $pdf->Image($image1, $pdf->GetX(), $pdf->GetY(), 33.78), 0, 0, 'L', false );

现在,如果周围的其他单元格移动,则该单元格将随内容上下移动.

Now the cell will move up and down with content if other cells around it move.

希望这会帮助同一条船上的其他人.

Hope this helps others in the same boat.

这篇关于用PHP和FPDF插入图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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