So I checked out the source and it didn't seem there was anyway for a link in the templates. I added the following code:
def write(self, pdf, x1=0, y1=0, x2=0, y2=0, text='', font="arial", size=1,
bold=False, italic=False, underline=False, align="", link='http://example.com',
foreground=0, *args, **kwargs):
if pdf.text_color!=rgb(foreground):
pdf.set_text_color(*rgb(foreground))
font = font.strip().lower()
if font == 'arial black':
font = 'arial'
style = ""
for tag in 'B', 'I', 'U':
if (text.startswith("<%s>" % tag) and text.endswith("</%s>" %tag)):
text = text[3:-4]
style += tag
if bold: style += "B"
if italic: style += "I"
if underline: style += "U"
align = {'L':'L','R':'R','I':'L','D':'R','C':'C','':''}.get(align) # D/I in spanish
pdf.set_font(font,style,size)
##m_k = 72 / 2.54
##h = (size/m_k)
pdf.set_xy(x1,y1)
pdf.write(5,text,link)
into templates.py and changed the line
- 'B': self.rect, 'BC': self.barcode, }
+ 'B': self.rect, 'BC': self.barcode, 'W' self.write, }
in the elements self handler. With this you can use a similar syntax to writing a text line in the elements dict object. Simply change type: 'T' to type: 'W' and add a link: 'http://code.google.com/p/pyfpdf/' to it or whatever link you want. I submitted this as a patch and it should be available in the next version. I left the x2 y2 in the parameters because I'm not sure if they are necessary for parsing or not but I believe the Write() method only uses x1 y1 if it's anything like the PHP version. K thx bye