Print Page | Close Window

How to handle table cells with large text

Printed From: Debenu Quick PDF Library - PDF SDK Community Forum
Category: For Users of the Library
Forum Name: I need help - I can help
Forum Description: Problems and solutions while programming with the Debenu Quick PDF Library and Debenu PDF Viewer SDK
URL: http://www.quickpdf.org/forum/forum_posts.asp?TID=4014
Printed Date: 22 Nov 24 at 7:27AM
Software Version: Web Wiz Forums 11.01 - http://www.webwizforums.com


Topic: How to handle table cells with large text
Posted By: bpeikes
Subject: How to handle table cells with large text
Date 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.



Replies:
Posted By: tfrost
Date Posted: 29 Jun 23 at 10:45AM
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.


Posted By: bpeikes
Date Posted: 29 Jun 23 at 2:09PM
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.


Posted By: tfrost
Date Posted: 30 Jun 23 at 10:25AM
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!


Posted By: bpeikes
Date Posted: 30 Jun 23 at 6:41PM
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.



Posted By: bpeikes
Date Posted: 28 Aug 23 at 2:55PM
I noticed that you said "the function handles pagination quite well". Which function handles pagination well?


Posted By: tfrost
Date Posted: 31 Aug 23 at 6:26PM
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.



Print Page | Close Window

Forum Software by Web Wiz Forums® version 11.01 - http://www.webwizforums.com
Copyright ©2001-2014 Web Wiz Ltd. - http://www.webwiz.co.uk