Skip to main content
Inspiring
September 22, 2022
Answered

Get the current page content

  • September 22, 2022
  • 2 replies
  • 538 views

Hi,

Although I have fetched the content of the InDesign document, I need the current page content. Could you please assist me with this?

To get the InDesign document's content, I used this.

var myDoc = app.activeDocument;
var myText= "";
for (var i = 0; myDoc.stories.length > i; i++)
myText += myDoc.textFrames[i].texts[0].contents;
alert("Document contains " + myText );

This topic has been closed for replies.
Correct answer Laubender

On: The contents of a page is stored in the array page.allPageItems.

The same with a spread. spread.allPageItems.

 

If you want to filter all text frames of a given page, you could loop the allPageItems array of a given page.

Then ask every item if it is a text frame after you "resolved" it with getElements() like that:

if( myActivePage.allPageItems[i].getElements()[0].constructor.name == "TextFrame" )
{
// do something.
};

There are other methods as well. You could loop the textContainers array of all given stories in the document and look for the value of parentPage. If this is identical to your active page store it to an array and when done with all textContainers of all stories loop the result array to do something with its contents.

 

Regards,
Uwe Laubender
( Adobe Community Expert )

2 replies

LaubenderCommunity ExpertCorrect answer
Community Expert
September 22, 2022

On: The contents of a page is stored in the array page.allPageItems.

The same with a spread. spread.allPageItems.

 

If you want to filter all text frames of a given page, you could loop the allPageItems array of a given page.

Then ask every item if it is a text frame after you "resolved" it with getElements() like that:

if( myActivePage.allPageItems[i].getElements()[0].constructor.name == "TextFrame" )
{
// do something.
};

There are other methods as well. You could loop the textContainers array of all given stories in the document and look for the value of parentPage. If this is identical to your active page store it to an array and when done with all textContainers of all stories loop the result array to do something with its contents.

 

Regards,
Uwe Laubender
( Adobe Community Expert )

Community Expert
September 22, 2022

Hi @MonishaRajendran ,

please specify what you mean by "current page".

Do you mean the active page on the active spread?

 

Explore:

 

var activeSpread = myDoc.layoutWindows[0].activeSpread;
var activePage = myDoc.layoutWindows[0].activePage;
var pageOffset = activePage.documentOffset;
var pageName = activePage.name;

 

 

Regards,
Uwe Laubender
( Adobe Community Expert )

 

EDITED CODE ABOVE: Changed app to myDoc.

Community Expert
September 22, 2022

NOTE: Edited my last reply.

 

Regards,
Uwe Laubender
( Adobe Community Expert )