I am new to classes in Python so please help me out. I am generating reports in pdf using fpdf package.
I am using sample code from the following to generate PDF page with footer.
https://pyfpdf.readthedocs.io/en/latest/Tutorial/index.html#header-footer-page-break-and-image
from fpdf import FPDF
class PDF(FPDF):
def header(self):
# Logo
self.image('logo_pb.png', 10, 8, 33)
# Arial bold 15
self.set_font('Arial', 'B', 15)
# Move to the right
self.cell(80)
# Title
self.cell(30, 10, 'Title', 1, 0, 'C')
# Line break
self.ln(20)
# Page footer
def footer(self):
# Position at 1.5 cm from bottom
self.set_y(-15)
# Arial italic 8
self.set_font('Arial', 'I', 8)
# Page number
self.cell(0, 10, 'Page ' + str(self.page_no()) + '/{nb}', 0, 0, 'C')
# Instantiation of inherited class
pdf = PDF()
pdf.alias_nb_pages()
pdf.add_page()
pdf.set_font('Times', '', 12)
for i in range(1, 5):
pdf.cell(0, 10, 'Printing line number ' + str(i), 0, 1)
pdf.output('tuto2.pdf', 'F')
This generates 5 pages. I want to add a list element in the footer.
list=['A','B','C','D','E']
for i in range(1, 5):
pdf.cell(0, 10, 'Printing line number ' + str(i)+list[i], 0, 1)
pdf.output('tuto2.pdf', 'F')
How do I pass this list to the Class? This list is generated in the derived class from the Class above.