Text alignment and borders

# Import FPDF class
from fpdf import FPDF

# Create instance of FPDF class
# Letter size paper, use inches as unit of measure
pdf=FPDF(format='letter', unit='in')

# Add new page. Without this you cannot create the document.
pdf.add_page()

# Remember to always put one of these at least once.
pdf.set_font('Times','',10.0) 

# Text will be left aligned in cell. This is the default alignment.
# Cell is 2.0 inches wide, will have a border and that is why we must now
# define a height of 0.15 inches
pdf.cell(2.0,0.15,'Hello World!', border=1)
pdf.ln(0.25)

# Text will be centered in cell.
# Cell is 3.0 inches wide, will have a border and that is why we must now
# define a height of 0.25 inches
pdf.cell(3.0,0.25,'Hello World!', border=1, align='C')
pdf.ln(0.50)

# Text will be right aligned in cell.
# Cell is 5.0 inches wide, will have a border and that is why we must now
# define a height of 0.50 inches
pdf.cell(5.0,0.50,'Hello World!', border=1, align='R')
pdf.ln(0.25)

# output content into a file ('F') named 'hello6.pdf'
pdf.output('hello6.pdf','F')

helloworld6

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s