Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get MultiCells in Pyfpdf Side by side?

Tags:

python-3.x

I am making a table of about 10 cells with headings in them. They will not fit accross the page unless I use multi_cell option. However I cant figure out How to get a multi_cell side by side. When I make a new one it autmatically goes to the next line

from fpdf import FPDF
import webbrowser

pdf=FPDF()
pdf.add_page()
pdf.set_font('Arial','B',16)
pdf.multi_cell(40,10,'Hello World!,how are you today',1,0)

pdf.multi_cell(100,10,'This cell needs to beside the other',1,0)

pdf.output('tuto1.pdf','F')


webbrowser.open_new('tuto1.pdf')
like image 864
WAMPS Avatar asked Mar 14 '23 13:03

WAMPS


1 Answers

You will have to keep track of x and y coordinates:

from fpdf import FPDF
import webbrowser

pdf=FPDF()
pdf.add_page()
pdf.set_font('Arial','B',16)

# Save top coordinate
top = pdf.y

# Calculate x position of next cell
offset = pdf.x + 40

pdf.multi_cell(40,10,'Hello World!,how are you today',1,0)

# Reset y coordinate
pdf.y = top

# Move to computed offset
pdf.x = offset 

pdf.multi_cell(100,10,'This cell needs to beside the other',1,0)

pdf.output('tuto1.pdf','F')

webbrowser.open_new('tuto1.pdf')
like image 159
Edwood Ocasio Avatar answered Mar 24 '23 05:03

Edwood Ocasio