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, ...

Get Programming PHP, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.