php TCPDF 在单行中左中右对齐
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15214136/
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
TCPDF Align Left Center Right in single line
提问by Benny
I want to create a footer for a PDF document that contains the date left aligned, the creator centered and the page right aligned. These should be in a single line. I tried the following code:
我想为包含日期左对齐、创建者居中和页面右对齐的 PDF 文档创建页脚。这些应该在一行中。我尝试了以下代码:
$this->Cell(0, 10, $date->format('d.m.Y'), 0, false, 'L', 0, '', 0, false, 'T', 'M');
$this->Cell(0, 10, 'Creator', 0, false, 'C', 0, '', 0, false, 'T', 'M');
$this->Cell(0, 10, 'Page '.$this->getAliasNumPage().'/'.$this->getAliasNbPages(), 0, false, 'R', 0, '', 0, false, 'T', 'M');
The creator is shifted to the right and overlays with the pages:
创建者向右移动并与页面重叠:


Does anybody have a solution for that problem?
有没有人有解决这个问题的方法?
采纳答案by Sean
You need to set the width of the Cell(), as according to the docs http://www.tcpdf.org/doc/code/classTCPDF.html#a33b265e5eb3e4d1d4fedfe29f8166f31your $date->format('d.m.Y')Cell()is extending to the right margin, forcing the other cells on the line to the right margin.
您需要设置 的宽度Cell(),根据文档http://www.tcpdf.org/doc/code/classTCPDF.html#a33b265e5eb3e4d1d4fedfe29f8166f31您$date->format('d.m.Y')Cell()正在扩展到右边距,强制行上的其他单元格到右边距。
$w (float) Cell width. If 0, the cell extends up to the right margin.
$w (float) 单元格宽度。如果为 0,则单元格向上延伸到右边距。
Try something like (may have to adjust based on font size)
尝试类似的东西(可能需要根据字体大小进行调整)
$this->Cell(20, 10, $date->format('d.m.Y'), 0, false, 'L', 0, '', 0, false, 'T', 'M');
$this->Cell(20, 10, 'Creator', 0, false, 'C', 0, '', 0, false, 'T', 'M');
$this->Cell(20, 10, 'Page '.$this->getAliasNumPage().'/'.$this->getAliasNbPages(), 0, false, 'R', 0, '', 0, false, 'T', 'M');
回答by Dean Sha
I ran into alignment issue with TCPDF too. I noticed that if you use x-coordinate as 0, then it will use the attribute 'R' for right alignment. But if it's set to a non zero value then it ignores the 'R' setting. Here's the statement I used for right alignment.
我也遇到了 TCPDF 对齐问题。我注意到如果您使用 x 坐标为 0,那么它将使用属性 'R' 进行右对齐。但如果它设置为非零值,则它会忽略“R”设置。这是我用于右对齐的语句。
$this->Cell(0, 9, 'Text-to-be-aligned-right', 0, false, 'R', 0, '', 0, false, 'T', 'M' );

