Repository navigation
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 |
Replies: 2 comments 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") |
|
Hello ! I'm commenting here because I thought this thread would have the answer I'm looking for but does not, and I found a way to do it that seems ok. Context : Problem : Solution : If you think of better ways to do this, feel free to suggest them, I'm not sure this is very clean. |
It's as simple as using your variable on the
textparameter ofcell().Here's an example: