Split all the tables values into 2 text frames
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);
}
}
}
