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

table-cell float:left fails PDF generation #276

Closed
gerpres opened this issue Feb 28, 2024 · 4 comments · Fixed by #283
Closed

table-cell float:left fails PDF generation #276

gerpres opened this issue Feb 28, 2024 · 4 comments · Fixed by #283
Assignees
Milestone

Comments

@gerpres
Copy link

gerpres commented Feb 28, 2024

for whatever-reason, a HTML/CSS I cannot fully control, applies float:left to a table-cell.
this results in the cell being rendered not as table-cell, but block.

this fails PDF generation with following error:

java.lang.ClassCastException: class org.xhtmlrenderer.render.AnonymousBlockBox cannot be cast to class org.xhtmlrenderer.newtable.TableCellBox (org.xhtmlrenderer.render.AnonymousBlockBox and org.xhtmlrenderer.newtable.TableCellBox are in unnamed module of loader 'app')
	at org.xhtmlrenderer.newtable.TableSectionBox.recalcCells(TableSectionBox.java:83)
	at org.xhtmlrenderer.newtable.TableBox.recalcSections(TableBox.java:204)
	at org.xhtmlrenderer.newtable.TableBox.calcMinMaxWidth(TableBox.java:154)
	at org.xhtmlrenderer.newtable.TableBox.layout(TableBox.java:221)
	at org.xhtmlrenderer.layout.BlockBoxing.layoutBlockChild0(BlockBoxing.java:321)
	at org.xhtmlrenderer.layout.BlockBoxing.layoutBlockChild(BlockBoxing.java:299)
	at org.xhtmlrenderer.layout.BlockBoxing.layoutContent(BlockBoxing.java:90)
	at org.xhtmlrenderer.render.BlockBox.layoutChildren(BlockBox.java:978)
	at org.xhtmlrenderer.render.BlockBox.layout(BlockBox.java:858)
	at org.xhtmlrenderer.render.BlockBox.layout(BlockBox.java:787)
	at org.xhtmlrenderer.layout.BlockBoxing.layoutBlockChild0(BlockBoxing.java:321)
	at org.xhtmlrenderer.layout.BlockBoxing.layoutBlockChild(BlockBoxing.java:299)
	at org.xhtmlrenderer.layout.BlockBoxing.layoutContent(BlockBoxing.java:90)
	at org.xhtmlrenderer.render.BlockBox.layoutChildren(BlockBox.java:978)
	at org.xhtmlrenderer.render.BlockBox.layout(BlockBox.java:858)
	at org.xhtmlrenderer.render.BlockBox.layout(BlockBox.java:787)
	at org.xhtmlrenderer.pdf.ITextRenderer.layout(ITextRenderer.java:229)

see following test:
PdfTest.txt

@asolntsev asolntsev self-assigned this Feb 28, 2024
@asolntsev asolntsev added this to the 9.6.0 milestone Feb 28, 2024
@asolntsev
Copy link
Contributor

asolntsev commented Feb 28, 2024

@gerpres Wow, thank you for the reproducible example. It helps a lot.
It's clearly a bug, will fix in 9.6.0

UPD Sorry, could not find a solution in 9.6.0, will try in 9.6.1

@asolntsev
Copy link
Contributor

@gerpres May I ask WHY do you want to use float: left for table cells? ChatGTP says it doesn't make sense. :)

In CSS, float: left is a property-value pair used to specify the horizontal alignment of an element within its container.

However, applying "float: left" to a table cell ( element) doesn't have any direct effect because table cells are part of a table layout system which doesn't interact with floats in the same way as block-level elements.

P.S. I still see a small difference with and without "float: left":
image

asolntsev added a commit that referenced this issue Mar 9, 2024
... even if they have style "float: left" or "float:right".

Marking style "float: left" to <td> element caused ClassCastException: we generated AnonymousBlockBox instead of TableCellBox for such element. But AFAIK this style is not applicable for table elements:

> However, applying "float: left" to a table cell ( element) doesn't have any direct effect because table cells are part of a table layout system which doesn't interact with floats in the same way as block-level elements.
@asolntsev
Copy link
Contributor

@gerpres Please take a look at #283
I think it solves your problem.

Does it seem reasonable?

asolntsev added a commit that referenced this issue Mar 9, 2024
... even if they have style "float: left" or "float:right".

Marking style "float: left" to <td> element caused ClassCastException: we generated AnonymousBlockBox instead of TableCellBox for such element. But AFAIK this style is not applicable for table elements:

> However, applying "float: left" to a table cell ( element) doesn't have any direct effect because table cells are part of a table layout system which doesn't interact with floats in the same way as block-level elements.
@gerpres
Copy link
Author

gerpres commented Mar 11, 2024

thx for your efforts @asolntsev. I'll give it a try ASAP>

@gerpres May I ask WHY do you want to use float: left for table cells? ChatGTP says it doesn't make sense. :)

I'm aware that floats on cells are not intended.

actually it's because of an unintended re-use of an existing CSS class in a framework-like-application, where an existing selector adds this float-styling. of course the selector could be modified to avoid applying floats on cells, but I was surprised that PDF generation fails due to such a styling.

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

Successfully merging a pull request may close this issue.

2 participants