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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 22:51:36  来源:igfitidea点击:

fpdf alignment of cells

phppdf-generationfpdf

提问by sipher_z

I'm trying to generate a PDF using fpdfand 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 0what 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 1which means a next cell is being placed underneath and not after (which the 0would do.)

在第二次调用之后,您注意到1这意味着下一个单元格被放置在下面而不是之后(这0会这样做。)