How to Center Text in FPDF?

不羁岁月 提交于 2021-02-07 06:59:10

问题


How can I have this generated text appear centered in the page.

Generated = $_POST method ... so I don't know how long will the text in input be. I need to have a pre-determined center parameter somehow.

Any ideas? Maybe like this:

MultiCell(0,$height,"text",0,'C') ?

回答1:


Normally it's $pdf->Cell(0, $height, "text", 0, 0, 'C'); but if you're doing it in a Header or Footer function it's $this->Cell(0, $height, "text", 0, 0, 'C'). Don't forget to declare $height as a global if you're doing this in a function() call.




回答2:


Thanks taur! This works for me:

$mid_x = 135; // the middle of the "PDF screen", fixed by now.
$text = $userFullName;
$pdf_file->Text($mid_x - ($pdf_file->GetStringWidth($text) / 2), 102, $text);



回答3:


This may work for you

MultiCell(0,$height,'You can<P ALIGN="center">center a line</P>',0,'C')



回答4:


$pdf->Text($mid_x-$pdf->GetStringWidth($text)/2,$y,$text);


来源:https://stackoverflow.com/questions/4742794/how-to-center-text-in-fpdf

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!