I am in struggle with FPDF - when I am looping over a dataframe and I want to put in the data in the page, the FPDF adds a new page, when the first page is full, and this is good - but then on the other pages, there are only one row per page, like:
PAGE 1: val 1, val 2, val 3, val 4, val 5, val 6
PAGE 2: val 7,
PAGE 3: val 8,
PAGE 4: val 9,
[...]
Here is my code:
pdf = PDF('L', 'mm', 'A4')
pdf.alias_nb_pages()
pdf.add_page()
pdf.set_font("Arial","",12)
pdf.content(df)
pdf.output('tuto2.pdf', 'F')
and this is my PDF
Class:
class PDF(FPDF):
def header(self):
self.set_font('Arial', 'B', 30)
self.cell(0,30,"HALLO PDF",0,0,"C")
self.ln(30)
def footer(self):
self.set_y(-20)
self.set_font('Arial', 'I', 8)
self.cell(0,10,"Seite " + str(self.page_no()) + "/{nb}",0,0,"C",0,"")
self.set_y(-10)
self.cell(0,10,"Dokument erzeugt am XXXX",0,0,"C",0,"")
def content(self,df):
y=30
for i in range(len(df)):
self.set_y(y)
self.cell(40,15,df['LG'].iloc[i],1,ln=0,align='C')
self.cell(40, 15, df['LGP'].iloc[i], 1, ln=0, align='C')
self.cell(40, 15, df['ZEIT'].iloc[i], 1, ln=1, align='C')
y=y+15
What is the problem here?
And maybe another one can answer me a quick question: Can I get the size of the body (like: pagesize - header - footer)?
Thanks