header contain a variable #1348
-
Hi together I found this library, and it's pretty cool to work with. please help me, it would be great if you put a code sniplet. Already many thanks. best regards Daniel |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
It's as simple as using your variable on the 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)
pdf = PDF()
pdf.set_margins(15, 20)
pdf.invoice = "Invoice n. 123"
pdf.add_page()
pdf.set_font("helvetica", size=14)
pdf.cell(text="Testing")
pdf.output("mytest.pdf") |
Beta Was this translation helpful? Give feedback.
It's as simple as using your variable on the
text
parameter ofcell()
.Here's an example: