1

有什么方法可以使 fpdi 中的文本居中,这样无论单词的长度如何,它始终居中?

4

4 回答 4

5

查看http://www.fpdf.de/funktionsreferenz/Cell/ - 参数 $align 采用“C”来居中对齐文本。

功能:

$fpdf->Cell(float w, float h, string txt, mixed border, integer ln, string align, integer fill, mixed link);

所以:

$fpdf->Cell(20,10,"Your Content",0,1,"C");

在当前位置放置一个宽度=20,高度=10 的单元格,并用给定的内容填充它

于 2011-01-09T08:55:44.187 回答
2

使用该getstringwidth功能可以计算出您的文本的宽度。将答案除以 2(得到中心位置),然后用它来抵消你的定位。

例如 :

pdf.text 89 - (pdf.getstringwidth("Your text here") / 2),132,"Your text here"

将文本定位在距页面左侧 89 毫米的中心

于 2014-03-21T12:24:41.710 回答
1

这可以帮助你http://www.fpdf.de/downloads/addons/41/

$pdf->WriteHTML('You can<P ALIGN="center">center a line</P>');
$pdf->MultiCell(75, 8, 'You can<P ALIGN="center">center a line</P>', 'L');
于 2012-11-22T18:21:51.953 回答
0
$fpdf->Cell($fpdf->w,$fpdf->h,"Your Content",0,1,"C");
于 2014-03-11T11:51:37.403 回答