Skip to content
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

Error in html table rendering when html tags are used inside a cell #845

Closed
stenci opened this issue Jul 10, 2023 · 4 comments
Closed

Error in html table rendering when html tags are used inside a cell #845

stenci opened this issue Jul 10, 2023 · 4 comments

Comments

@stenci
Copy link

stenci commented Jul 10, 2023

The following code should create a table with 3 rows and 3 columns, instead the 2nd row contains 5 columns.

The two font tags are correctly interpreted and they have the expected effect on the font, but they also seem to be interpreted as td.

Example code

from fpdf import FPDF

pdf = FPDF()
pdf.add_page()
pdf.write_html("""
<table border=1>
  <thead>
    <tr>
      <th>Column 1</th>
      <th>Column 2</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td align="center">Cell 1</td>
      <td align="center">Cell 2</td>
    </tr>
    <tr>
      <td align="center">Cell 1</td>
      <td align="center">Some <font size=7>small</font> and some <font size=20>large</font></td>
    </tr>
    <tr>
      <td align="center">Cell 1</td>
      <td align="center">Cell 2</td>
    </tr>
  </tbody>
</table>
""")
pdf.output("html.pdf")

Example output
image

Environment

  • Operating System: Windows
  • Python version: 3.7
  • fpdf2 version used: 2.7.4
@Lucas-C
Copy link
Member

Lucas-C commented Jul 10, 2023

Hi @stenci and thank you for the precise bug report 👍

<font> tags are currently not supported inside <td> elements.

FYI, when using the latest version of fpdf2 from the git master branch (cf. https://pyfpdf.github.io/fpdf2/#installation ),
you would get the following error from the fpdf/table.py module:

fpdf.errors.FPDFException: Inconsistent column count detected on row 3: it has 5 columns, whereas the top row has 2.

We could improve that error message, by generating a more explicit one in the html.py module in that case.

Adding support for <font> tags in <td> elements would be a lot more difficult,
as it would mean supporting table sub-cells.

For reference, this issue is related to issue #640: both reveal fundamental limitations of fpdf2 HTML renderer,
that does not support rendering of nested elements, whereas the HTML spec totally allows them.

We should probably add a mention about this fundamental limitation in our documention
( PRs are welcome to add a mention about this on https://pyfpdf.github.io/fpdf2/HTML.html )

@Lucas-C
Copy link
Member

Lucas-C commented Jul 11, 2023

I opened PR #852 in order to improve our documentation and generate a clearer error message

Would you like to review it @stenci? 😊

Lucas-C added a commit that referenced this issue Jul 11, 2023
@stenci
Copy link
Author

stenci commented Jul 11, 2023

I opened PR #852 in order to improve our documentation and generate a clearer error message

Would you like to review it @stenci? 😊

I am not familiar with github. I clicked on the PR link on your message, I noticed a "review changes" button, clicked on it and approved.
The changes seem to fully address the problem, and some more.
Thank you for addressing this, and doing it so quickly.

@stenci stenci closed this as completed Jul 11, 2023
Lucas-C added a commit that referenced this issue Jul 11, 2023
@Lucas-C
Copy link
Member

Lucas-C commented Jul 11, 2023

Thank you for your feedback @stenci 🙂

I merged the PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants