Put a link on a picture? #769
Replies: 4 comments 2 replies
-
Hi @Rapid1898-code , As stated on https://pyfpdf.github.io/fpdf2/Links.html#hyperlink-with-fpdflink: "The if you look at this line in your code: pdf.link(x=0, y=0, w=width, h=line_height, link="https://github.com/PyFPDF/fpdf2") You may notice the x, y, w, and h arguments. They allow you to exactly specify the clickable area on the page. |
Beta Was this translation helpful? Give feedback.
-
Hello - thanks to the reply - i changed the code to this:
But the text is still before the image. |
Beta Was this translation helpful? Give feedback.
-
from fpdf import FPDF
pdf = FPDF()
pdf.add_page()
# Add image
pdf.image("image.jpg", x=10, y=10, w=100)
# Add link over image
pdf.set_xy(x=10, y=10)
pdf.set_text_color(0, 0, 255)
pdf.set_font("Arial", size=12)
pdf.cell(w=100, h=30, txt="Click here to go to GitHub", ln=0, align="C", link="https://github.com/PyFPDF/fpdf2")
pdf.output("hyperlink.pdf") |
Beta Was this translation helpful? Give feedback.
-
Hello - thanks a lot to both of you. |
Beta Was this translation helpful? Give feedback.
-
Hello - i try to import an image and put a link on the image with the following code and the attached files:
When i create the pdf - see attached
hyperlink.pdf
the link is allways before the image.
Is it somehow possible to put the link directly on the image - if possibly centered in the middle?
Beta Was this translation helpful? Give feedback.
All reactions