FPDF将文本左对齐,居中和右对齐 [英] FPDF align text LEFT, Center and Right
本文介绍了FPDF将文本左对齐,居中和右对齐的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有三个单元格,我正在尝试将文本对齐到左",中"和右".
I've have three cells and i'am trying to align the text to Left, Center and Right.
function Footer()
{
$this->SetY( -15 );
$this->SetFont( 'Arial', '', 10 );
$this->Cell(0,10,'Left text',0,0,'L');
$this->Cell(0,10,'Center text:',0,0,'C');
$this->Cell( 0, 10, 'Right text', 0, 0, 'R' );
}
当我输出我的PDF文件时,center text
会自动正确对齐.
看起来是这样:
When I ouput my PDF file, center text
get automatically aligned right.
This is how it looks:
有人可以告诉我我在这里做错了什么以及如何解决这个问题?
Can somebody tell me what I'm doing wrong here and how I can fix this issue?
推荐答案
如果将Cell方法的ln-parameter设置为0,则将Cell调用后的新位置设置为每个单元格的右侧.在最后2个单元格调用之前重置x坐标:
The new position after a Cell call will be set to the right of each cell if you set the ln-parameter of the Cell method to 0. You have to reset the x-coordinate before the last 2 Cell calls:
class Pdf extends FPDF {
...
function Footer()
{
$this->SetY( -15 );
$this->SetFont( 'Arial', '', 10 );
$this->Cell(0,10,'Left text',0,0,'L');
$this->SetX($this->lMargin);
$this->Cell(0,10,'Center text:',0,0,'C');
$this->SetX($this->lMargin);
$this->Cell( 0, 10, 'Right text', 0, 0, 'R' );
}
}
这篇关于FPDF将文本左对齐,居中和右对齐的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文