-
Notifications
You must be signed in to change notification settings - Fork 251
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Creating Links in Table Cells #1031
Comments
Hi and welcome @demiurgepy 🙂
Thank you! It makes me happy to know that this library helped you 😊
You did not provide a code snippet that I can easily test 😢 |
I was able to craft a minimal script reproducing your issue, and this is indeed a bug: #!/usr/bin/env python3
from fpdf import FPDF
TABLE_DATA = (
("First name", "Last name", "Age", "City"),
("Jules", "Smith", "34", "San Juan"),
("Mary", "Ramos", "45", "Orlando"),
("Carlson", "Banks", "19", "Los Angeles"),
("Lucas", "Cimon", "31", "Angers"),
)
pdf = FPDF()
pdf.set_font("helvetica", size=8)
pdf.add_page()
with pdf.table() as table:
for data_row in TABLE_DATA:
row = table.row()
for item in data_row:
row.cell(text=item, link="https://py-pdf.github.io/fpdf2/")
pdf.output("issue_1031.pdf") |
This was a regression in I'm creating a PR to fix this now. Thank you for the report @demiurgepy! |
@allcontributors please add @demiurgepy for bug |
I've put up a pull request to add @demiurgepy! 🎉 |
Sorry for not getting that minimal code over to you in time. Thanks a bunch for your quick response though – you guys are amazing! |
Hi again FPDF Team, I'm back with an update and further inquiry about the table hyperlink issue I mentioned earlier. This time, I've noticed that when I place a hyperlink in the third column of a table, it strangely extends to the first column as well. This is happening despite my attempts to limit the hyperlink to just the third column. A minimal script: from fpdf import FPDF
TABLE_DATA = (
("First name", "Last name", "Age", "City"),
("Jules", "Smith", "34", "San Juan"),
("Mary", "Ramos", "45", "Orlando"),
("Carlson", "Banks", "19", "Los Angeles"),
("Lucas", "Cimon", "31", "Saint-Mahturin-sur-Loire"),
)
pdf = FPDF()
pdf.add_page()
pdf.set_font("Times", size=16)
with pdf.table() as table:
for i, data_row in enumerate(TABLE_DATA):
row = table.row()
for j, datum in enumerate(data_row):
if j == 2 and i > 0:
row.cell(text=datum, link='https://py-pdf.github.io/fpdf2/')
else:
row.cell(datum)
pdf.output('table.pdf') In this script, the hyperlink is intended only for the "Age" column, but it also activates in the "First name" column. I'm hoping to get some insight or guidance on how to address this issue. Thanks again for your time and assistance. |
Hi @demiurgepy
I tried your code, and I do not reproduce the problem you are describing, sorry! Are you using the latest version of
|
No, you were right, there was still a bug related to this in Sadly, it was not included as part of today's release: https://github.com/py-pdf/fpdf2/releases/tag/2.7.7 |
Hello FPDF Team,
First and foremost, I'd like to express my immense gratitude for the effort put into developing the FPDF library. It's an incredible tool that has been immensely helpful.
I am currently facing an issue with creating clickable hyperlinks in a table. Specifically, I have a table with three columns, where the second column consists of links. When these links extend over a line break, PDF readers only recognize and make the part of the link before the line break clickable. I need a solution that allows the entire link to be clickable.
I have followed the tutorial in the FPDF Tables Documentation, particularly the section about adding links to cells in a table:
row.cell(..., link="https://py-pdf.github.io/fpdf2/") row.cell(..., link=pdf.add_link(page=1))
However, the links in the table cells are not becoming clickable. They work fine outside the table using
pdf.cell(text=text, link=link),
but inside the table, they seem to be unresponsive, only the text is updated. Here is the snippet of my code:I've also tried to replicate the example provided in the documentation, but I'm encountering the same issue – the text in the table cells is not clickable.
Could you please provide some guidance or suggestions on how to resolve this issue? Any help would be greatly appreciated!
Thank you in advance for your time and assistance.
The text was updated successfully, but these errors were encountered: