-
Notifications
You must be signed in to change notification settings - Fork 253
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 layout will break if the content of a cell requires more than one page #1142
Comments
Hi @SMMousaviSP When I tested your code with latest version of Given this size of your input text, it seems difficult to handle it "properly". |
Hello @Lucas-C What I had in mind was something like this. This is the default behavior of Microsoft Word. I understand that if a text is too long, it may not make much sense to store it in a table. However, imagine a scenario where most of the time all cells of the table are going to be just one line or 2 to 3 lines and using the table would make sense and is a nice visual representation but once or twice a cell might become longer than expected. This will prevent the use of tables in automated tasks since we know it is possible for the table to break (even if it happens rarely). As you saw in my first example, in the case of exceedingly long texts, it doesn't only break that specific row and the layout of the whole table gets broken. |
Hi @SMMousaviSP I had a closer look at the code, and I think this will be a difficult addition. Basically, it would mean to A) detect this situation and B) split the row into several smaller rows, which is something I am bit relunctant to do, because a consequence would be for the table final rows count to be unpredictable for the user... A first step / easier solution could be to A) detect this situation and B) raise an error in that case. What do you think about this strategy @SMMousaviSP? |
I have some ideas for how to handle rendering a long cell across multiple pages, although I see the potential for a lot of edge cases where the desired behaviour is not necessarily clear. I'm happy to give it a go and see how far I get with a simplistic approach. |
@Lucas-C Thank you for taking time and looking into this issue. Would there be a reasonable solution to resolve this error when it happens? For example by somehow figuring out how much of the text is fitting to be able to either cut the rest or make a new row for that manually? Otherwise to be honest I prefer to have the broken table compared to not having any PDF at all. Also I want to point out that I initially thought that the page break within a row is possible and this is just a bug cause I saw this comment in
If there was not supposed to be any page break, why the left and right borders are segments and not continuous. |
You are very welcome to give it a try @mjasperse! 🙂
Good idea @SMMousaviSP, dropping extraneous text seems easier to implement than splitting the cell/row.
That's simply because we support page breaks inside tables, with rows spanning over several pages and we then repeat the heading row at the top of every page, but not inside cells 🙂 |
Since |
OK! |
Hey @Lucas-C , Can I have a go at this one? |
Well, it depends if @mjasperse wants to continue working further on this subject. |
@shoaib-moeen you can give it a try! My simple idea broke rather quickly on the test suite because of scenarios like table cells with multiple "overflowing" cells, or images. If there is only one long cell, that is fairly easy to handle but I think the general-case complexity grows quickly. Working on my initial implementation raised the following points that I would appreciate your thoughts on @Lucas-C
Maybe I'm overthinking the edge cases and the primary use-case here is handling one long cell and ensuring a sensible PDF is generated at all. However the first two points affect the existing test-suite cases. Unfortunately I doubt I will have time to work on this implementation in the next two months because of work commitments, sorry that I wasn't able to come up with something faster. |
IMHO, for now there is no need for fine-grained control there, but we should leave it open for further improvements later on:
No need for user-specified settings there, we could have a simple rule for now that cells containing images do not TRIGGER cell breaks, and if a cell break occurs on a row with images in other cells, those images will be rendered on the first line.
Those are valid concerns, and I do not have a simple answer to them.
The complexity of this scenario makes me wonder if we should really support this logic in
Agreed for throwing an exception, that's the best option. |
The typographical terms are "widows" (left-over line(s) after a page/column break) and "orphans" (left behind line(s) before a page/column break). High-end layout software usually allows to specify a minimum number for each (or no break if there are fewer lines than either limit).
This is an interesting idea, but will obviously only be enforcible if the cell contents fit on one page.
I would try to center content over the complete height of the column, no matter how many pages it spans. This makes the solution independent of whether the vertically centered content actually fits on any one of the involved pages. Top and bottom valigned content is obvious.
Let's cross that bridge when we get there... 😉 You may notice that I keep referring to a future conversion to text regions. This will involve pretty much a rewrite of the base mechanics of how tables are built, since text regions use different concepts than the currently used multi_cells. The new code will be more stringently structured, delegate more functionality to lower levels, and thus hopefully simplify the overall architecture of the module. I had started working on this conversion several months ago. But then the table code repeatedly sprouted new features left and right, which made it difficult to keep track and adapt the rewrite accordingly. |
Thank you for your insight @gmischler 🙂
Sure, I agree with this idea, as long as it does not stall
Maybe a next step regarding text regions could be to split the work and define clear GitHub issues that other contributors could pick up and work on? If I'm not mistaken, the initial design for text regions came from this discussion 2 years ago: #339 |
When the content of one cell within a table is too long, the layout will break.
table.pdf
Minimal code
Environment
Please provide the following information:
fpdf2
version used: 2.7.8The text was updated successfully, but these errors were encountered: