NORM
NORM

Reputation: 245

center text in fpdi?

Is there any way to center text in fpdi so that no matter what length the word has its always centered?

Upvotes: 1

Views: 7473

Answers (4)

Jess--
Jess--

Reputation: 21

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

Upvotes: 2

Sarkanyolo
Sarkanyolo

Reputation: 15

$fpdf->Cell($fpdf->w,$fpdf->h,"Your Content",0,1,"C");

Upvotes: 1

Balram Singh
Balram Singh

Reputation: 1754

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');

Upvotes: 1

roman
roman

Reputation: 11278

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

Upvotes: 5

Related Questions