by
Patwos >> Thu, 4 Mar 2004 8:54:34 GMT
Another approach is to print the report "a line at a time" by working out how much of the text will fit on 1 line using getTextExtent a character at a time, taking note of the last "white space" position to ensure words don't break in the middle of the word. You need to handle embedded CrLfs and situations where a single string with no "white space" is wider than the width you are allowing for a single line.
If you have multiple columns if does introduce another complication to the printing calculations as you now may have multiple columns for which you need to do the getTextExtent calculations to handle wrapping onto the next "line" of each respective control.
I tend to do the app.printer.print for each line rather than working out how many lines will fit onto the remaining space of the current page. It doesn't appear to be too inefficient doing the printing a line at a time even for reasonably large reports and makes the calculations easier, particularly when you have multiple columns that may potentially go over multiple rows. Having said that, once you have the code written it makes it much easier to produce multiple column reports where you are not sure how many lines each column will have and/or where you need to keep printing information in just some of the columns while other columns have finished printing their information several lines earlier.
eg: I ended up with several generic methods along the lines of the following and didn't have to concern myself anymore with handling columns of different lengths:
printMultiColumnLine1Up( column1Text : String );
printMultiColumnLine2Up( column1Text, column2Text : String ); printMultiColumnLine3Up( column1Text, column2Text, column3Text : String ); printMultiColumnLine4Up( column1Text, column2Text, column3Text, column4Text : String );
These methods all handled spanning onto the next page automatically, including repeating their subheadings with (ctnd) appended automatically etc. Makes adding new multi-column reports a breeze.
Hope that helps,
Pat.