I need some assistance regarding table overflow. I have two tables that have to fit into their own boxes. The trick here is both tables are too long to fit the area they are supposed to populate. TableA needs to be in the first block which is currently absolute positioned. TableB uses the header footer settings in the master page to control its overflow. What is happening now is that the TableA is overflowing on top of TableB. How can I get Connect to break table A and send the remainder to a new page and place it in the the same box/area as the first page?
I have included a sample data mapper, template and sample output PDF’s. The PDF’s show the incorrect and correct output.
What I am noticing with some jobs that I am converting to use in Connect is that table A can span over 3 or 4 pages while table B mostly spans over two pages. The desired output needs both tables to span over multiple pages. These are municipal statements.
The only way I can think of doing that is calculating the tables length in a script. (Not sure if there is a way to do that in the data mapper and extract said value into a new field called tableALength etc.) Then based on what area is available for each table, since they are fixed per job, one can calculate how many pages each table would need. In this case Table A’s max rows is 7. Using…
var l = record.tables.tableA.length;
var pages = Math.round(l/7);
35 / 7 = 5 pages for TableA.
TableB pages could be also calculated the same…
var l = record.tables.tableB.length;
var pages = Math.round(l/26);
51 / 26 = 2 (once rounded up like above) pages for TableB.
I see we can use an Action step within the repeat step to get the total number of rows a detail table has and then calculate the number of pages the detail table will use. So we get two fields in the data mapper containing their num pages needed.
TableA pages:
var pages = Math.round(steps.currentLoopCounter/7);
record.fields.tableAPagesNeeded = pages;
TableB pages:
var pages = Math.round(steps.currentLoopCounter/26);
record.fields.tableBPagesNeeded = pages;
EDIT: Perhaps better field names instead of tableBRowCount, tableAPagesNeeded.
Attached a quick and dirty script to clone the table and repeat if over an x amount of pages. I modified the template and assigned your table image to the media and set a pdf with white pages as the section background.
The control script sets the number of pages to be read from the PDF which forces the minimum number of pages for the print section (set the minimum number of pages will become a feature in a future version). This number is derived from your data.
Again its quick and dirty but it seems to work. I prefer not to use DOM actions in the scripting, performance could be improved by converting the rows to text and perform replace() actions but let us see if this works for you.
That is very impressive. Looks to be working great. I’m in the process of grabbing some records from live data and will apply this to them to see how it behaves. Will report back asap.
The error was gone but I was missing a page and a few lines of data for that table. So I changed this line in the control strip to below.
var numpages = Math.round(record.tables.tableA.length / 5);
The table is now correct. However in my tests I only populated the table using one column from the data. You mentioned some performance issues and converting rows to text. Can you explain what you mean by this because performance is always key.
The scripts in my sample perform manipulations directly on the DOM. Typically things go faster when converting a DOM element to a string and perform a plain JavaScript search and replace. Take a look at the link below for more information and inspiration:
See the attached template. I did the following to improve the performance:
Specified the execution scope for the scripts in the tableA folder. The scripts now run for the Section 1 only and are not evaluated for master pages. To set the scope right mouse click the folder in the Scripts panel and choose Properties. Select the sections/masters the script should apply to and click OK.
The rows are not translated to a string and text is added using the replace() command.
I didn’t delete the original script so you can compare the difference using the Profile Scripts feature.
Thanks for taking the time optimise this. I am very impressed at the help this forum provides. Great community. I was attempting my own optimisation too.
This minor change got the script profiler from 596555.49 to 173641 milliseconds. I also thought of adding a boolean field to the data mapper and using javascript set it to true or false. Basically the javascript will calculate the length of the table in question and thus only execute these scripts should the table need to overflow. This means the script will only be used if needed thus increasing performance.
Off topic question: How did you indent your code on the forums. The block quote on my side disables the Increase Indent button and the incorrect formatting is driving me nuts.
The difference between our scripts is: In my approach I collect the HTML for the personalized rows in a string and append it to the DOM once per table. You append each personalized row to the table (e.g. hitting the DOM more often).
Thanks for the feedback, I’ll def take a look at your suggestion!
Thanks for the explanation. Regarding my suggestion above, the table names would have to be a drop down list rather than a label since Connect would have to identify the tables to overflow.