Cell()

	
	Cell(float w [, float h [, string txt [, mixed border [, int ln [, string align [, boolean fill [, mixed link]]]]]]])

Prints a cell (rectangular area) with optional borders, background color and character string. The upper-left corner of the cell corresponds to the current position. The text can be aligned or centered. After the call, the current position moves to the right or to the next line. It is possible to put a link on the text. If automatic page breaking is enabled and the cell goes beyond the limit, a page break is done before outputting.

w

Cell width. If 0, the cell extends up to the right margin.

h

Cell height. Default value: 0.

txt

String to print. Default value: empty string.

border

Indicates if borders must be drawn around the cell. The value can be either a number:

or a string containing some or all of the following characters (in any order):

ln

Indicates where the current position should go after the call. Possible values are:

Putting 1 is equivalent to putting 0 and calling Ln() just after. Default value: 0.

align

Allows to center or align the text. Possible values are:

fill

Indicates if the cell background must be painted (true) or transparent (false). Default value: false

link

URL or identifier returned by AddLink().

	
	// Set font
	$pdf->SetFont('Arial','B',16);
	// Move to 8 cm to the right
	$pdf->Cell(80);
	// Centered text in a framed 20*10 mm cell and line break
	$pdf->Cell(20,10,'Title',1,1,'C');

Consider the following example -

	$str = "Lorem ipsum dolor sit amet, \n consectetur adipisicing elit, sed do eiusmod
			tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
			quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
			consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
			cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
			proident, sunt in culpa qui officia deserunt mollit anim id est laborum. ";
	$pdf->Cell(0,0,$str);

The above produce the following output. The rest of the text is hidden. Even if you insert a \n within the text, it won't work. Even if you increase the height of the Cell, the line won't wrap, it will just increase the height of the Cell.

So use Cell() only when you want to limited text that can be fitted within a single line. The following example uses the border -

	$str = "Lorem ipsum dolor sit amet";
	$pdf->Cell(0, 10, $str, 1);

MultiCell()

	
	MultiCell(float w, float h, string txt [, mixed border [, string align [, boolean fill]]])

This method allows printing text with line breaks. They can be automatic (as soon as the text reaches the right border of the cell) or explicit (via the \n character). As many cells as necessary are output, one below the other.

Text can be aligned, centered or justified. The cell block can be framed and the background painted.

w

Width of cells. If 0, they extend up to the right margin of the page.

h

Height of each cells.

txt

String to print.

border

Indicates if borders must be drawn around the cell block. The value can be either a number:

or a string containing some or all of the following characters (in any order):

align

Sets the text alignment. Possible values are:

fill

Indicates if the cell background must be painted (true) or transparent (false). Default value: false.

Here is an Example -

	$str = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod 
	tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,quis nostrud exercitation 
	ullamco laboris nisi ut aliquip ex ea commodoconsequat. Duis aute irure dolor in reprehenderit in 
	voluptate velit essecillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat 
	cupidatat nonproident, sunt in culpa qui officia deserunt mollit anim id est laborum.";
	$pdf->MultiCell(0, 10, $str, 1, 'J');

And it produces the following result -

Write()

	
	Write(float h, string txt [, mixed link])

This method prints text from the current position. When the right margin is reached (or the \n character is met) a line break occurs and text continues from the left margin. Upon method exit, the current position is left just at the end of the text. It is possible to put a link on the text.

So it allows to write a chunk of text, alter the font style, then continue from the exact place we left it. On the other hand, you cannot justify it.

h

Line Height

txt

String to print

link

URL or identifier returned by AddLink()

	
	// Begin with regular font
	$pdf->SetFont('Arial','',14);
	$pdf->Write(5,'Visit ');
	// Then put a blue underlined link
	$pdf->SetTextColor(0,0,255);
	$pdf->SetFont('','U');
	$pdf->Write(5,'www.fpdf.org','http://www.fpdf.org');

Here is an Example -

	$str = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor
	 incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,quis nostrud exercitation ullamco
	 laboris nisi ut aliquip ex ea commodoconsequat. Duis aute irure dolor in reprehenderit in voluptate 
	 velit essecillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat nonproident, 
	 sunt in culpa qui officia deserunt mollit anim id est laborum.";
	$pdf->Write(5, $str);

The above example produces the following output -

Text()

	
	Text(float x, float y, string txt)

Prints a character string. The origin is on the left of the first character, on the baseline. This method allows to place a string precisely on the page, but it is usually easier to use Cell(), MultiCell() or Write() which are the standard methods to print text.

x

Abscissa of the origin.

y

Ordinate of the origin.

txt

String to print.

	
	$pdf = new FPDF();
	$pdf->SetFont('Arial','B',16);
	
	$pdf->AddPage();
	$pdf->Text(50, 50, "Hello Santanu");		

	$pdf->Output('helo.pdf', 'D');

GetStringWidth()

	
	float GetStringWidth(string s)

Returns the length of a string in user unit. A font must be selected.

s

The string whose length is to be computed.

	
	$pdf = new FPDF();
	$pdf->SetFont('Arial','B',16);
	$stringWidth = $pdf->GetStringWidth("Santanu");
	return $stringWidth; // 22.267333333333

Using SetFont() is required in order to use GetStringWidth().

Ln()

	
	Ln([float h])

Performs a line break. The current abscissa goes back to the left margin and the ordinate increases by the amount passed in parameter.

h

The height of the break. By default, the value equals the height of the last printed cell.

SetFont()

	
	SetFont(string family [, string style [, float size]])

Sets the font used to print character strings. It is mandatory to call this method at least once before printing text or the resulting document would not be valid. The font can be either a standard one or a font added via the AddFont() method.

The method can be called before the first page is created and the font is kept from page to page. If you just wish to change the current font size, it is simpler to call SetFontSize().

The font definition files must be accessible. They are searched successively in:

Example using FPDF_FONTPATH:

	define('FPDF_FONTPATH','/home/www/font');
	require('fpdf.php');

If the file corresponding to the requested font is not found, the error "Could not include font definition file" is raised.

family

Family font. It can be either a name defined by AddFont() or one of the standard families (case insensitive):

style

Font style. Possible values are (case insensitive):

The default value is regular. Bold and italic styles do not apply to Symbol and ZapfDingbats.

size

Font size in points. The default value is the current size. If no size has been specified since the beginning of the document, the value taken is 12.

Note that the font size is given in points, not millimeters (or another user unit); it's the only exception.

	
	// Times regular 12
	$pdf->SetFont('Times');
	// Arial bold 14
	$pdf->SetFont('Arial','B',14);
	// Removes bold
	$pdf->SetFont('');
	// Times bold, italic and underlined 14
	$pdf->SetFont('Times','BIU');

SetFontSize()

	
	SetFontSize(float size)

Defines the size of the current font.

size

The size (in points).

AddFont()

	
	AddFont(string family [, string style [, string file]])

Imports a TrueType, OpenType or Type1 font and makes it available. It is necessary to generate a font definition file first with the MakeFont utility. The definition file (and the font file itself when embedding) must be present in the font directory. If it is not found, the error "Could not include font definition file" is raised.

family

Font family. The name can be chosen arbitrarily. If it is a standard family name, it will override the corresponding font.

style

Font style. Possible values are -

file

The font definition file. By default, the name is built from the family and style, in lower case with no space.

	
	$pdf->AddFont('Comic','I');
	// Same as
	$pdf->AddFont('Comic','I','comici.php');