I am trying to make an infographic and I want to add social media links to it. I started off with reportlab, since this module supposedly can add links to output pdf files, but I can’t get it work. I am not engaded with reportlab, so any other working library is ok, as long as I can create a PDF with it with clickable hyperlinks.
SOCIAL LINKS
link_url = ‘https://www.facebook.com/’
link_rect = (100, 100, 200, 120)
Draw a yellow rectangle over the linked area
pdf_canvas.setFillColorRGB(1, 1, 0) # Set the fill color to yellow (RGB: 1, 1, 0)
pdf_canvas.rect(*link_rect, fill=1) # Draw the rectangle
Create a clickable hyperlink
pdf_canvas.linkURL(link_url, link_rect, relative=1)
PDF SAVE
pdf_canvas.save()
Reportlab is properly imported, I don’t get any error message, the code runs and the PDF is generated. The yellow rectangle (which I added just to see where the link is supposed to be) is there, only there is no clickable hyperlink.
I tried to solve this with AI (Codeium – I code in VS Code), but it ran out of ideas.
Gábor is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.