Reputation: 1131
I have created a pdf file with FPDF in python. i use a header and footer and call them with "add_page". my first page is a cover page. is there an elegant way to ignore the header in the first page?
Any help will be appreciated!
from fpdf import FPDF
class PDF(FPDF):
# 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()
##Page 1
pdf.add_page()
##Page 2
pdf.add_page()
pdf.output('tuto2.pdf', 'F')
Upvotes: 1
Views: 4378
Reputation: 169304
You may achieve this by adding a conditional statement for the header and footer. Example of conditional footer below:
class PDF(FPDF):
# Page footer
def footer(self):
# Do not print footer on first page
if self.page_no() != 1:
# 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')
Upvotes: 3