MCcereal
MCcereal

Reputation: 66

PyPDF hyperlink

Is there a way to add a hyperlink in a PDF?

For example:

url = "https://www.google.com/"

# This cell should be a hyperlink to google
pdf.cell(20, 30, "This text redirects to google", 0, 0, 'C')

I found add_link & set_link in the documentation but this only works as an internal link.

Upvotes: 2

Views: 1266

Answers (1)

Frank
Frank

Reputation: 1249

Solution:

from fpdf import FPDF

pdf = FPDF()
pdf.add_page()
pdf.set_font('Arial', 'B', 16)
pdf.cell(40, 10, 'Hello World!',link ="https://www.google.com")

pdf.output('tuto1.pdf', 'F')

Click on "Hello World" to jump to google.

You may have noticed the color of the text is still black. You can adjust the color by specifying the parameters in set_font

Upvotes: 2

Related Questions