How to center text in FPDF?

How can I create this generated text centered on the page.

Generated method = $_POST ... so I don’t know how long the text in the input file will be entered. I need to somehow predefine the center parameter.

Any ideas? Maybe like this:

 MultiCell(0,$height,"text",0,'C') ? 
+4
source share
4 answers

Usually it is $pdf->Cell(0, $height, "text", 0, 0, 'C'); but if you do this in the header or footer function, this is $this->Cell(0, $height, "text", 0, 0, 'C') . Do not forget to declare $height global, if you do it in the function call ().

+13
source

Thank you 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); 
+5
source

This may work for you.

 MultiCell(0,$height,'You can<P ALIGN="center">center a line</P>',0,'C') 
+2
source
 $pdf->Text($mid_x-$pdf->GetStringWidth($text)/2,$y,$text); 
+1
source

Source: https://habr.com/ru/post/1336240/


All Articles