Closed demiurgepy closed 12 months ago
Hi and welcome @demiurgepy 🙂
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.
Thank you! It makes me happy to know that this library helped you 😊
However, the links in the table cells are not becoming clickable. [...] Here is the snippet of my code:
You did not provide a code snippet that I can easily test 😢 Please provide a minimal reproducible example, that does not require to guess what is your surrounding code and the data you are using: https://stackoverflow.com/help/minimal-reproducible-example
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 fpdf2
release 2.7.6, brought by this PR: #797
I'm creating a PR to fix this now.
Thank you for the report @demiurgepy!
@allcontributors please add @demiurgepy for bug
@Lucas-C
I've put up a pull request to add @demiurgepy! :tada:
Sorry for not getting that minimal code over to you in time. Thanks a bunch for your quick response though – you guys are amazing! It's really cool to see such active and helpful support in the community 🤜🤛
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
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.
I tried your code, and I do not reproduce the problem you are describing, sorry! It correctly produces a PDF with an hyperlink set only on the numeric values of the 3rd column.
Are you using the latest version of fpdf2
from the master
branch?
You can install it this way:
pip install git+https://github.com/py-pdf/fpdf2.git@master
Thanks Lucas for your prompt response and for taking the time to test the code. I appreciate your efforts to help diagnose the issue.
After receiving your message, I made sure to install the latest version of fpdf2 from the master branch as you suggested. However, I'm still encountering the same issue where a portion of the first column becomes clickable, despite the hyperlink being intended only for the third column. This behavior persists in the generated PDF, with the first few letters in the first column responding as part of the hyperlink.
Interestingly, a few other developers have also tested this on their systems and have reported experiencing the same issue. It seems to be a consistent behavior across different environments. This is a visual example, to give you a clearer idea:
Could there be a specific environment or PDF viewer factor at play here? Or might there be a subtle aspect of the library's behavior that we're overlooking?
Could there be a specific environment or PDF viewer factor at play here? Or might there be a subtle aspect of the library's behavior that we're overlooking?
No, you were right, there was still a bug related to this in fpdf2
😅
I fixed that in #1061
Sadly, it was not included as part of today's release: https://github.com/py-pdf/fpdf2/releases/tag/2.7.7
But if you install fpdf2
from this repo master
branch, you should be able to test if that solves your problem.
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.