JavaScript InDesign - Detect table in linked text frames
Hello,
I have a script that worked very nicely until I started using a table. The table is in multiple linked text frames. My script successfully removes table rows that are empty, but then I am left with some empty pages. My function to remove these empty pages is not working anymore, because it is now a table instead of plain text. It used to work by identifying whether all text frames on the page were empty, and then delete the page.
However, when I find the contents of the table in the text frame, it will give me the full contents of the table for the first page, and then claim that the (linked) text frame on the next page is empty.It also claims there is no table on the second and third pages (I assume due to the linking of text frames).
My question, then, how I can obtain the information that there is, in fact, a table inside the text frames on the subsequent pages?
E.g.:
app.activeDocument.pages[2].textFrames.everyItem().tables.everyItem().contents;returns the full table content, rather than just the content on page 2.
And:
app.activeDocument.pages[3].textFrames.everyItem().tables.everyItem().getElements().length;returns 1 for the first page and 0 for the subsequent pages.
Alternative methods to go about this are also welcome.
I attach a screenshot for how to table looks on the two subsequent pages.
Many thanks in advance,
Heidi
Screenshot 2025-12-02 130319.png
