Skip to content

header contain a variable #1348

Answered by andersonhc
dll-live asked this question in Q&A
Jan 15, 2025 · 1 comments · 1 reply
Discussion options

You must be logged in to vote

It's as simple as using your variable on the text parameter of cell().

Here's an example:

from datetime import datetime
from fpdf import FPDF

class PDF(FPDF):
    def header(self):
        self.set_font("helvetica", style="B", size=15)
        # print the date on the left
        self.set_xy(self.l_margin, 5)
        self.cell(w=self.epw, text=datetime.today().strftime('%Y-%m-%d'), align="L")
        # print the invoice number on the right
        self.set_xy(self.l_margin, 5)
        self.cell(w=self.epw, text=self.invoice, align="R")
        # draw a line under the header
        self.line(self.l_margin, 12, self.w - self.r_margin, 12)
        self.set_xy(self.l_margin, self.t_margin)
…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@dll-live
Comment options

Answer selected by dll-live
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants