I have an inDesign document with 10 pages filled with text. The text is styled with different Paragraph Styles, of which some are relevant for building a custom table of contents.
There are two relevant Paragraph Styles, "Header1" and "Header2" from which I am trying to build my own Table of Contents, which I want to export in a text file.
The relevant information I need to get is the text which is styled with "Header1" and "Header2" and the corresponding page number.
I tried to achieve this via GREP and was halfway successful, but GREP scans the whole document and not page by page.
Is there a way to go through all styled texts by Paragraph Style page by page?
Thanks in advance!
Yes.
Give a look into the Object model of the InDesign API.
You have the class Pages so iterate over all Pages, using method length
Then, inside this loop, for each page get all the TextFrames
For each textFrame use the Class Paragraph to iterate over each TextFrame
Inside each paragraph, get the attributes you want.