Skip to main content
Known Participant
April 7, 2016
Question

Remove "empty" linked text frames at the end of documents

  • April 7, 2016
  • 3 replies
  • 1839 views

Hi all,

I want to write a script to clean up the "empty" text frames and pages at the end of the document,

these text frames and pages are there because I have formatted the table and text correctly after I placing a word doc, and content shrink dramatically.

I know technically these "empty" text frames are not empty because they are linked to the part with tables and text in previous text frames, so I cannot use the delete empty frames script...

This topic has been closed for replies.

3 replies

tpk1982
Legend
April 7, 2016

this one delete the empty pages

var myPages = app.documents[0].pages.everyItem().getElements();

for(var i=0;i<myPages.length;i++){

    if(myPages.pageItems.length==0){

    myPages.remove();

    }

}

tpk1982
Legend
April 7, 2016

Try this

var myFrame = app.activeDocument.textFrames.everyItem().getElements();

for (var j = 0 ; j < myFrame.length; j++) {

        if(myFrame.contents == ""){

        myFrame.remove();

        }

}

VWuAuthor
Known Participant
April 7, 2016

Hi tpk1982,

Thank you for your scripts!

They seem pretty straightforward, however when I tried it, InDesign hangs indefinitely.

The document contains linked text frames, with lengthy tables inside, some of the text frames are multiple columns with gutters in between.

tpk1982
Legend
April 7, 2016

Maybe the file size slower the script performance. Just save file as ".idml" and open the file again and run the script

just a try..

b91823603
Participating Frequently
April 7, 2016

Hi,

Check text frame contents, if it is empty then remove the text frame then check all other text frames in a page. If all text frames are empty and pageItems length is also zero then remove the page.