Skip navigation
Learner X
Currently Being Moderated

Want to Delete Blank Page(empty text Frame)

Jul 4, 2012 7:29 AM

Hi All,

 

I want to delete blank page in my active document.

 

With the use of forum i get the below script:

 

var myDoc = app.activeDocument;

var myPages = myDoc.pages.length;

for (var i = myPages-1;  i>=0; i--){

    if(myDoc.pages[i].pageItems.length==0 && myDoc.pages[i].guides.length ==0){

        myDoc.pages[i].remove();

        }

    }

 

But my Doubt is if empty text frame or empty figure frame is available in any page means that page also want to be delete.

 

Can anyone give the solution for my requirement.

 

Regards

Learner_X

 
Replies
  • Currently Being Moderated
    Jul 4, 2012 11:11 AM   in reply to Learner X

    @Learner_X – the problem here is: at what point is a text frame considered empty?

     

    Example 1: if text frames are threaded over several pages and a table is running from one to the other your script might detect an empty text frame even it isn't (it's holding a part of the table), if you are testing for emptyness with something like that "textFrame[i].insertionPoints.length === 1" for the last text frame.

     

    Example 2: can we consider a colored rectangle as empty?

     

    Occasionaly this questions arise in this forum. Search for "empty page" or "empty text frame" etc.pp. to see that there is no universal answer to that…

     

    Uwe

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 4, 2012 2:35 PM   in reply to Learner X
     
    |
    Mark as:
  • Currently Being Moderated
    Jul 4, 2012 10:52 PM   in reply to Harbs.

    @Harbs – your script checks "emptiness" of a text frame by looking at its "contents" property.


    So if you take my "Example 1" above, a page will be deleted inspite of holding a text frame with a part of a table that is threaded to another page.

     

    So it would be wise to add another check  if there is a new text overflow after removing the pages.

     

    Uwe

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 4, 2012 11:01 PM   in reply to Learner X

    Hi All,

        I've the codes...

    If it help, use it...

     

    doc=app.activeDocument;

    pageObj=doc.pages.item(0);

    txtObj=pageObj.textFrames.item(0);

    var temp=doc.pages.length;

    for(var i=0;i<temp;i++)

    {

        if(doc.pages[i].textFrames.item(0)!=null)

        {

                if(doc.pages[i].textFrames[0].contents=="")

                {

                    doc.pages[i].remove();

                    i=i-1;

                    temp--;

                }

                else

                {

                   

                }

        }

        else if(doc.pages[i].pageItems.item(0)!=null)

        {

            alert("Something");

        }

        else

        {

          doc.pages[i].remove();

          i=i-1;

          temp--;

        }

    }

     

    Thanks and Regards,

    Vel.

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 5, 2012 12:53 AM   in reply to Velprakash

    Hello Vel,

     

    I have tested your above JS code.

     

    1. Have you tried the single page document without any objects in the pages. its throw the error.

    2. 2nd page have two text frames 1st text frame have some contents and 2nd frame is no content. Your script will delete the page. this is wrong.

    3. You have check 1st page if there is no content the pages will never delete using manually or scripting also. You have to try manually delete in 1st page. this is also error.

     

    FYI: Please go through the HARBS code is checking the expect the 1st page will check the contents exits or not and then delete the pages.

     

    Harbs code UWE cross checked and give to the some additional check to add in harbs code.

     

    thx,

    csm_phil

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 5, 2012 2:30 AM   in reply to csm_phil

    Hi CS M_Phill,

           First of all, I thank you to mention all the bugs in my JS code. I'm trying to overcome it.

          The issues You mentioned can be solved by using simple below codes.

    (For Pages with No Text)

     

    doc=app.activeDocument;

    pageObj=doc.pages.item(0);

    txtObj=pageObj.textFrames.item(0);

    var temp=doc.pages.length;

    var count = 0;

    if(doc.pages.length==1)

    {

        alert("Document contains only one page. So can't delete if it's empty page or with Some contents...");

        exit(0);

        }

    for(var i=0;i<temp;i++)

    {

        var txtfrmLen = doc.pages[i].textFrames.length;

        for(var j=0;j<txtfrmLen;j++)

        {

            if(doc.pages[i].textFrames[j].contents=="")

            {

                count++;

                }

            }

        if(count == txtfrmLen)

        {

            doc.pages[i].remove();

            i = i-1;

            temp = temp-1;

            }

        count = 0;

        }

     

    Thanks and Regards,

    Vel.

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 5, 2012 3:49 AM   in reply to Velprakash

    @Velprakash – a word of caution here:

     

    textFrames[j].contents == ""

     

    is not sufficient for checking empty text frames if you deal with tables that are threaded through several text frames.
    See my "Example: 1" in answer#1.

     

    Try it out yourself…

     

    Meanwhile I did a little digging in the forum.
    Marijan Tompa came up with a very clever solution for a test:

     

    http://forums.adobe.com/message/4005252#4005252

     

    Read the whole thread; no wonder I had a déjà vu after reading the title of this thread.

     

    Uwe

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points