Ligamena
Ligamena

Reputation: 89

Is there a way to assign a variable in pdf.cell() text string in python

Is there a way i can assign a variable instead of hard coding in the pdf.cell() text string? This is how my code looks like:

pdf.cell(200, 0, txt="MENZ INVESTMENTS ", ln=9, align="L")
pdf.cell(190, 5, txt="Tel:061295000", ln=10, align="R")

instead of hard coding:

txt="MENZ INVESTMENTS "
txt="Tel:061295000"

I would like to assign variable:

name = driver.find_element_by_id('nameId').text
cell = driver.find_element_by_id('cellPhone').text

So that my code look like this:

pdf.cell(200, 0, txt=name, ln=9, align="L")
pdf.cell(190, 5, txt=cell, ln=10, align="R")

Upvotes: 1

Views: 989

Answers (1)

Adam
Adam

Reputation: 11

I have just found out how to do this in case you are still trying...

I created a time stamp with the variable, timestamp, that I wanted to include at the top of the PDF when it was created. It works with the following:

pdf.cell(200, 10, txt = "Date and time: " + str(timestamp), ln = 0, align = 'L')

So in your case it would be:

nameid = "fred"
cellid = "Tel:0123456789"

pdf.cell(200, 10, txt= str(nameid), ln = 1, align = 'L')
pdf.cell(200, 10, txt= str(cellid), ln = 1, align = 'L')

This printed

fred Tel:0123456789

in the PDF.

Upvotes: 1

Related Questions