[Python] Fpdf header and background

Discussão em 'Python' iniciado por Stack, Fevereiro 17, 2025.

  1. Stack

    Stack Membro Participativo

    I need to create a pdf with header, footer and background color. Tge following code is generating all 3, but it seems the footer is getting behind the pdf rect

    from fpdf import FPDF

    class PDF(FPDF):
    def header(self):
    self.set_font(family='Helvetica', size=8)
    self.cell(0, 10, 'test_header', align='L')

    def footer(self):
    self.set_y(-15)
    self.set_font(family='Helvetica', size=8)
    self.cell(0, 10, 'test_footer', align='L')

    pdf = PDF()
    pdf.add_page()
    pdf.set_font("Times", size=12)

    # BG
    pdf.set_fill_color(r=249, g=247, b=242)
    pdf.rect(h=pdf.h, w=pdf.w, x=0, y=0, style="F")```

    With the above only footer is visible but without it, both are visible.

    How can I achieve the desired outcome?

    Continue reading...

Compartilhe esta Página