center text in fpdi?
Is there any way to center text in fpdi so that no matter what l开发者_C百科ength the word has its always centered?
look at http://www.fpdf.de/funktionsreferenz/Cell/ - the parameter $align takes 'C' to center align text.
function:
$fpdf->Cell(float w, float h, string txt, mixed border, integer ln, string align, integer fill, mixed link);
so:
$fpdf->Cell(20,10,"Your Content",0,1,"C");
places a cell with width=20, height=10 at your current position and fills it with the given content
Use the getstringwidth
function to work out how wide your text will be.
Divide the answer by 2 (to get the center position), then use that to offset your positioning.
For example :
pdf.text 89 - (pdf.getstringwidth("Your text here") / 2),132,"Your text here"
will position the text centered on 89mm from the left of the page
This may help you 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');
$fpdf->Cell($fpdf->w,$fpdf->h,"Your Content",0,1,"C");
精彩评论