php fpdf 单元格对齐
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5911891/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
fpdf alignment of cells
提问by sipher_z
I'm trying to generate a PDF using fpdf
and I'm having a small problem
我正在尝试使用生成 PDF fpdf
,但遇到了一个小问题
I need to have 2 cells, like the following:
我需要有 2 个单元格,如下所示:
------------------------- -------------------------
| Address Line 1 | Version |
| Address Line 2 | 1.0 |
| City | 06/05/2011 |
------------------------- -------------------------
I've tried using MultiCell()
but with no luck.
我试过使用MultiCell()
但没有运气。
$address = '
Address Line 1
Address Line 2
City
Postcode';
$pdf->MultiCell(133.5, 2.7, $address, 'L', 'L');
$version = '
Version
1.0
06/05/2011';
$pdf->MultiCell(53.5, 2.7, $version, 'R', 'R');
I thought that I could possibly set the 'float' as it was left or right, which is what the docs say, but this doesn't seem to work. It just lists the Version multicell below the address and not to the right of it.
我认为我可以将“浮动”设置为向左或向右,这是文档所说的,但这似乎不起作用。它只是在地址下方而不是在它的右侧列出了版本多单元格。
Does anyone have any idea why this would be?
有谁知道为什么会这样?
Thanks
谢谢
回答by Joshua - Pendo
http://www.fpdf.org/en/tutorial/tuto5.htm:
http://www.fpdf.org/en/tutorial/tuto5.htm:
Just use:
只需使用:
$pdf->Cell(width, height, text, border, position-next-cell, alignment);
So this means, to add a column afterwards 'position-next-cell' should be 0
what you're looking for is probably:
所以这意味着,在 'position-next-cell' 之后添加一列应该是0
你正在寻找的可能是:
$pdf->Cell(133.5, 2.7, $address, 0, 0, 'L');
$pdf->Cell(53.5, 2.7, $version, 0, 1, 'L');
After the 2nd call you noticed the 1
which means a next cell is being placed underneath and not after (which the 0
would do.)
在第二次调用之后,您注意到1
这意味着下一个单元格被放置在下面而不是之后(这0
会这样做。)