Copy link to clipboard
Copied
Hi,
This script iterates through all text frames in the active layer of the active document and checks whether any table in the text frame exceeds the page height. If a table does exceed the page height, the script adds a new page and splits the table into two frames.
The script defines two functions: IterateDocument, and AddColumnToTable.
"IterateDocument" is the main function that loops through each text frame in the active layer of the active document and calls the AddColumnToTable function for each frame.
"AddColumnToTable" is another helper function that is called for each table in the text frame that exceeds the page height. It resizes the text frame to be half the height of the table, adds a new page after the current page, and creates a new text frame on the new page. It then threads the new text frame to the original text frame and fits both frames to their content.
The problem is that I am unable to split a table into two frames for more than two tables. As well as the contents of the two tables being swapped. Could you please guide me on how to resolve this issue?
IterateDocument();
function IterateDocument()
{
for(myCounter = 0; myCounter < app.activeDocument.activeLayer.textFrames.length; myCounter++)
{
myStory = app.activeDocument.activeLayer.textFrames.item(myCounter);
AddColumnToTable (myStory);
}
}
function AddColumnToTable (mySel)
{
var geometricbound = mySel.geometricBounds;
var addPageLocation = 0;
for (var j = 0; j < mySel.tables.length ; j++)
{
var table = mySel.tables[j];
if(app.activeDocument.documentPreferences.pageHeight<table.height)
{
geometricbound[2] = geometricbound[0] + table.height/2;
geometricbound= [95.891, 37.5, 730.458, 576];
mySel.geometricBounds = geometricbound;
var newFrame = app.activeDocument.pages.add(LocationOptions.AFTER, app.activeDocument.pages[addPageLocation] );
var textframe = app.activeDocument.pages[addPageLocation+1].textFrames.add({
geometricBounds:[95.891, 37.5, 730.458, 576]
});
mySel.nextTextFrame = textframe ;
textframe .fit(FitOptions.frameToContent);
mySel.fit(FitOptions.frameToContent);
}
}
}
Copy link to clipboard
Copied
Hi,
I will start by saying that I have not run you code, will try and do that later, but a couple of points I have noticed from your code.
1. Are all your tables on the first page of any document ? as you use this variable (
var addPageLocation = 0;
And it doesn't change between runs?
2. you have a number of lines of code that don't appear to be used
var geometricbound = mySel.geometricBounds;
geometricbound[2] = geometricbound[0] + table.height/2;
// the above two lines work with the bounds,
// and then the line below just overwrites them
geometricbound= [95.891, 37.5, 730.458, 576];
and then when you could use it, you just put in the number anyway.
I understand that you may be working through how to get this to work, but I would remove code that you don't need, as you can always put it back in later, and it just adds confusion to other ( me) when they are trying to understand your code.
I think the addPageLocation should be calculated from the page where the table lives, as if I understand the problem correctly, you want any table where the table is longer than the page to continue onto the next page ?
Copy link to clipboard
Copied
Hi @BarlaeDC
The unused lines in the code have been removed. The geometric bounds have been given to get the text frames within the page. But now I'm able to split the tables into multiple text frames when the table height exceeds the page height. Now, I'm experiencing a problem: "AddColumnToTable calls recursively when the text frame doesn't overflow".
var addPageLocation = 0;
function AddColumnToTable(mySel, addPageLocation, originalTable) {
var gb = [95.891, 37.5, 730.458, 576];
mySel.geometricBounds = gb;
var newPage = app.activeDocument.pages.add(LocationOptions.AFTER, app.activeDocument.pages[addPageLocation]);
var textframe = app.activeDocument.pages[addPageLocation + 1].textFrames.add({
geometricBounds: [95.891, 37.5, 730.458, 576]
});
mySel.nextTextFrame = textframe;
textframe.fit(FitOptions.frameToContent);
if (textframe.overflows == true ) {
addPageLocation = addPageLocation + 1;
AddColumnToTable(textframe, addPageLocation, originalTable);
}
}