title: inDesign Script: Get Text and Page number of Text styled with a certain Paragraph Style using JavaScript
body: <p>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.</p>
  
  <p>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.</p>
  
  <p>The relevant information I need to get is the text which is styled with "Header1" and "Header2" and the corresponding page number.</p>
  
  <p>I tried to achieve this via GREP and was halfway successful, but GREP scans the whole document and not page by page.</p>
  
  <p>Is there a way to go through all styled texts by Paragraph Style page by page?</p>
  
  <p>Thanks in advance!</p>