I use a sample code from fpdf2-documentation for producing pdf files. In order to use Turkish letters I added a ttf – font. It works.
Changing the font of the header and footer is not possible. Adding a new font doesn’t work here.
Is there a way for changing the header and footer fonts?
The code is as follows:
from fpdf import FPDF
class PDF(FPDF):
def header(self):
# Setting font: helvetica bold 15
self.set_font("helvetica", "B", 15)
# Moving cursor to the right:
self.cell(80)
# Printing title:
self.cell(30, 10, "Title", border=1, align="C")
# Performing a line break:
self.ln(20)
def footer(self):
# Position cursor at 1.5 cm from bottom:
self.set_y(-15)
# Setting font: helvetica italic 8
self.set_font("helvetica", "I", 8)
# Printing page number:
self.cell(0, 10, f"Page {self.page_no()}/{{nb}}", align="C")
# Instantiation of inherited class
pdf = PDF()
pdf.add_page()
pdf.add_font("OpenSans-Regular", style="", fname=r"C:\Users\Anwender\AppData\Local\Microsoft\Windows\Fonts\OpenSans-Regular.ttf")
pdf.set_font("OpenSans-Regular", size=12)
for i in range(1, 41):
pdf.cell(0, 10, f"Printing line number {i}", new_x="LMARGIN", new_y="NEXT")
pdf.output("new-tuto2.pdf")`
New contributor
ender is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.