O'Reilly logo

Programming PHP, 3rd Edition by Rasmus Lerdorf, Peter MacIntyre, Kevin Tatroe

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Text

Text is the heart of a PDF file. As such, there are many options for changing the appearance and layout of text. In this section, we’ll discuss the coordinate system used in PDF documents, functions for inserting text and changing text attributes, and font usage.

Coordinates

The origin (0,0) in a PDF document with the FPDF library is in the top-left corner of the defined page. All of the measurements are specified in points, millimeters, inches, or centimeters. A point (the default) is equal to 1/72 of an inch, or 0.35 mm. In the code in Example 10-2, we change the defaults of the page dimensions to inches with the FPDF() class instantiation-constructor method. The other options with this call are the orientation of the page (portrait or landscape) and the page size (typically Legal or Letter). The full options of this instantiation are shown in Table 10-1.

Table 10-1. FPDF options

FPDF() constructor parameters

Parameter options

Orientation

P

Portrait (default)

L

Landscape

Units of measurement

pt

Point (1/72 of an inch) (default)

in

Inch

mm

Millimeter

cm

Centimeter

Page size

Letter (default)

 

Legal

 

A5

 

A3

 

A4 or a customizable size (see FPDF documentation)

Also in Example 10-2, we use the ln() method call to manage what line of the page we are on. The ln() method can take an optional argument instructing it how many units to move (units being the defined unit of measurement in the constructor call). In our case, we have defined the page to be in inches, so we are moving down in inch measurements. Further, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required