5 Replies Latest reply on Feb 1, 2014 4:25 PM by Colin Flashman

    Delete Text Frame out of page

    creativejoan0425 Level 1



      I want to delete text frame either is blank or have text that out of the page in all opened document, below script can delete all text frame in all opened document, but I want to keep the text frame inside the page, can anyone help me?


      var myDoc = app.documents.length;
      for (var k= myDoc -1; k >= 0; k--) {

      var myStories = app.documents[k].stories.everyItem().getElements();

      for (i = myStories.length - 1; i >= 0; i--){
          var myTextFrames = myStories[i].textContainers;
          for (j = myTextFrames.length - 1; j >= 0; j--)    {

        • 1. Re: Delete Text Frame out of page
          Daniel Sterchi Level 3

          Hi creativejoan0425


          Give this script a try:


          It delets all Textframe which are totaly off a page

          It delets all empty Textframes


          Script works for multiple document and multiple pages.






          function main() {

               var myDocs = app.documents.everyItem().getElements();

               for (var j = myDocs.length -1;  j >= 0; j--) {

                    var myTextFrames = myDocs[j].textFrames.everyItem().getElements();


                    for (var i = myTextFrames.length -1; i >= 0 ; i--) {


                          // is null, if the textfame is totaly off the pagae

                         if (myTextFrames[i].parentPage == null) myTextFrames[i].remove();


                         // deletes empty Textframe

                         else if (myTextFrames[i].contents == "") myTextFrames[i].remove();


                    } // for

                    myDocs[j].save() // Save the actual Document

                    myDocs[j].close()     // close the actual Document

               } // for

          } // main



          Kind Regard


          Dani (from Switzerland)

          • 2. Re: Delete Text Frame out of page
            Jump_Over Level 5

            creativejoan0425 wrote:

            ... that out of the page...


            If "out of page" means do not overlap with page bounds ==> textFrame.parentPage == null, so:


                 mDoc = app.documents,
                 dLen = mDoc.length,
                 cDoc, cParent, cLen;
            while (dLen-->0) {
                 cDoc = mDoc[dLen];
                 cParent = cDoc.textFrames.everyItem().parentPage;
                 cLen = cParent.length;
                 while (cLen -->0)
                      if (cParent[cLen] == null)




            Message was edited by: Jump_Over :) yeap Dani, didnt see your post :)

            • 3. Re: Delete Text Frame out of page
              creativejoan0425 Level 1

              If i want to out of page + document bleed?




              • 4. Re: Delete Text Frame out of page
                Laubender Adobe Community Professional & MVP

                @creativejoan0425 – see the following blog post:


                Marc Autret

                Clean up your Pasteboard!




                • 5. Re: Delete Text Frame out of page
                  Colin Flashman Adobe Community Professional

                  Be careful of any script that says it "deletes empty textframes". While a textframe may not contain any text, it may contain:


                  • a fill;
                  • a stroke;
                  • a text wrap feature;
                  • type on a path;
                  • be grouped to another object
                  • a link to an anchored object
                  • part of a multi-state object or a button


                  feathering my own nest, there is a script on my blog that is a collaboration of many authors that may help:




                  its purpose: delete empty text frames, that is all. It won't target any extra objects on the pasteboard such as pictures or graphics that aren't used... in fact it doesn't target the pasteboard at all, that's where Marc Autret's script is useful