• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Split all the tables values into 2 text frames

Explorer ,
Feb 17, 2023 Feb 17, 2023

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);
         }
        } 
}

 

TOPICS
How to , Scripting

Views

359

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 27, 2023 Feb 27, 2023

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 ?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 28, 2023 Feb 28, 2023

Copy link to clipboard

Copied

LATEST

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". 

AddColumntoTable has 3 parameters (mysel -> text frames in the active document, addlocationpage -> page added when the text frame overflows, table -> current tables in the active document).

 

 

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);
  }
}

 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines