[Python] FPDF: insert variable into PDF

Discussão em 'Python' iniciado por Stack, Abril 13, 2025.

  1. Stack

    Stack Membro Participativo

    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")

    Continue reading...

Compartilhe esta Página