Do you own a Debenu Quick PDF Library version 7, 8, 9, 10, 11, 12, 13 or iSEDQuickPDF license? Upgrade to Debenu Quick PDF Library 14 today!
How to handle table cells with large text |
Post Reply |
Author | |
bpeikes
Beginner Joined: 23 Apr 18 Status: Offline Points: 11 |
Post Options
Thanks(0)
Posted: 28 Jun 23 at 5:10AM |
We've got code for rendering tables across multiple pages, with repeating headers. There is one place where we are having some issues with though, and that is if a cell has so much text it does not fit on a single page.
What's the best way of handling this? Our code currently checks to see the last row rendered, and if there are any more rows to render, starts a new page, (optionally renders header by inserting a row) and then continues to render the table. When a string in a cell is too long, DrawTableRows returns the height of the header row, and since we still have rows to process, we create a new page, and render a header, etc.... To add some complications, we are adding html line break into some of the fields, based on if the user has entered multiline text. |
|
tfrost
Senior Member Joined: 06 Sep 10 Location: UK Status: Offline Points: 437 |
Post Options
Thanks(0)
|
It is difficult to advise you without knowing how you plan to deal with a cell that does not fit on a page - how will you deal with splitting it or reducing its size. My approach would be to start by making the header row an entirely separate 1-row table on each page, to avoid modifying the table while you are rendering it. I am a bit surprised that that even works. But then you have a number of options when 0 rows fit, including omitting the header table on that page and trying again; rendering the too-large content in a separate 1-row table with a smaller font and skipping that row for the next page in the main table; finding a way of splitting it; or something else. Again, the details of how you implement your solution is totally dependent on what you decide your solution will be for your specific content and audience.
|
|
bpeikes
Beginner Joined: 23 Apr 18 Status: Offline Points: 11 |
Post Options
Thanks(0)
|
It sounds like the library does not have a way to render tables across pages then.
I would want the row to continue to be rendered on the next page, or have the abilty to clip the text. Are you saying that if we add a new page to have a table render across multiple pages, we should start a new table? That doesnt feasable if you are trying to render a table with hundreds of rows across multiple pages. |
|
tfrost
Senior Member Joined: 06 Sep 10 Location: UK Status: Offline Points: 437 |
Post Options
Thanks(0)
|
No, I was not saying start a new table. It seems reasonable to me that handling a "row" which needs more than a page should not be a built-in feature of a function designed to handle "tables" in general. The function handles pagination quite well, but this seems a special case, especially since you said that some of these big rows may also contain HTML in which line-breaks are present.
So my suggestion was that you deal with an outlier row needing an internal page break independently of the table function, and then carry on rendering the rest of the original table on later pages. How you handle this special row depends on your application. It seems that it should be straightforward to do this, but this depends on how complicated the content is. That's my response to your original question, but there may be other users here who have more experience with "tables" than I do. You will find that QPDF has functionality in many unexpected areas, but this task may be stretching its capability!
|
|
bpeikes
Beginner Joined: 23 Apr 18 Status: Offline Points: 11 |
Post Options
Thanks(0)
|
The main issue I'm having is that there isn't a good way to know how to split it up. The call DrawHTMLTextBox returns the remainder of the html that wont fit into the box, and there is another function GetHTMLTextHeight, that will give you the height of the box needed to render HTML.
The issue is that there is no call where you can specify a box, and get information about what part of of the HTML that wont fit in a box. If that was the case, then I could find which column was causing the row to not be drawn, split the text, and then copy the remainder into the new row. |
|
bpeikes
Beginner Joined: 23 Apr 18 Status: Offline Points: 11 |
Post Options
Thanks(0)
|
I noticed that you said "the function handles pagination quite well". Which function handles pagination well?
|
|
tfrost
Senior Member Joined: 06 Sep 10 Location: UK Status: Offline Points: 437 |
Post Options
Thanks(0)
|
The one you are asking about: DrawTableRows. It is fine if you have smallish rows and do not mind about leaving a bit of blank space at the bottom when a row does not fit. But if you want to divide up the text in a row and split it across multiple pages, you have to decide on your policy for splitting it, and then perhaps use a function such as DrawHTMLTextBox to fill the gap, which will return the LeftOverText which will then fit on the next page. It will involve some experimentation to get it to work as you want, but with this function, QPDF does provides "a call where you can specify a box, and get information about what part of of the HTML that wont fit in a box". You might have to do a test render on a spare page to get this function to tell you where to split the text, before to adding it to the table, but it seems that QPDF can split it for you. The documentation does not say how smart it is about not splitting in the middle of words, but if you discover a split word you could always move all of it to the next page.
|
|
Post Reply | |
Tweet
|
Forum Jump | Forum Permissions You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum |
Copyright © 2017 Debenu. Debenu Quick PDF Library is a PDF SDK. All rights reserved. About — Contact — Blog — Support — Online Store