问题
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