在fpdf单元格上添加换行符 [英] Adding linebreak on fpdf cells
问题描述
我必须添加换行符才能使图像彼此出现.我已经尝试了以下方法,但是它不起作用.
I must add a linebreak for my images to appear after each other. I have tried the following but it does not work.
$rs['imagepath'] = $imagepath;
$pdf->Image("{$imagepath}\n");
下面是输出图像的原始代码,但是只输出第一个索引,而第二个和第三个图像却不显示...:(
The original code to output the images is below, but it outputs only the first index and the second and third images does not come up... :(
$rs['imagepath'] = $imagepath;
$pdf->Image("{$imagepath}");
结果在如下所示的foreach循环中:
The result is in a foreach loop like this:
foreach($select as $index => $rs)
{
$rs['imagepath'] = $imagepath;
$pdf->Image("{$imagepath}");
}
推荐答案
我认为您的代码有误,请尝试下面的代码遍历$rs
数组.在当前代码中,您的$imagepath
变量始终保持不变.然后可以将\n
字符打印到pdf以打印新行
I think your code has a mistake, try the below code to iterate over the $rs
array. in the current code, your $imagepath
variable is always remain same. you can then print a \n
characters to pdf for printing new lines
foreach($select as $index => $rs)
{
$imagepath = $rs['imagepath'];
$pdf->Image("{$imagepath}");
}
我在另一个堆栈溢出线程上发现了这一点
If you are using fpdf, in order to be able to use line breaks you will need to use a multi-line text cell as described here.
如果使用此选项,则应正确解释和转换文本中的换行符.
If you use this, then line breaks in your text should be interpreted and converted correctly.
一个简单的例子:
$pdf->Multicell(0,2,"This is a multi-line text string\nNew line\nNew line");
在这里,2是多行文本框的高度.我不知道测量的单位是什么,或者您是否可以将其设置为0并忽略它.如果一开始不起作用,也许可以尝试大量使用.
Here, 2 is the height of the multi-line text box. I don't know what units that's measured in or if you can just set it to 0 and ignore it. Perhaps try it with a large number if at first, it doesn't work.
这篇关于在fpdf单元格上添加换行符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!