Chris Dav
Chris Dav

Reputation: 71

FPDF: insert variable into PDF

Using FPDF2 and Python3 to create a report. Would like to insert a string into a PDF but cannot see how to do it. Just cannot find the syntax.

Something simple like:

from fpdf import FPDF, HTMLMixin

class PDF(FPDF, HTMLMixin):
    pass 
name="Chris"

pdf = PDF()
pdf.add_page()
pdf.write_html("""
<h1>My name -{name} should print here</h1>
""")
pdf.output("htmlnew.pdf")

Upvotes: 0

Views: 1094

Answers (1)

KJDII
KJDII

Reputation: 861

Did you try using an f string:


from fpdf import FPDF, HTMLMixin

class PDF(FPDF, HTMLMixin):
    pass 
name="Chris"
... 

pdf.write_html(f"""<h1>My name {name} should print here</h1>""")

...


Upvotes: 1

Related Questions