• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Find empty pages in doc

Community Beginner ,
Jul 01, 2021 Jul 01, 2021

Copy link to clipboard

Copied

Hi community. 

I am trying to find empty pages in doc. 
Here is the sample part to count the pages in doc, but I also need to check if page is empty or not.

var doc = app.ActiveDoc;
var bodyPage = doc.FirstBodyPageInDoc;
var counter = 0;
while (bodyPage.ObjectValid()) {
  counter++;
  bodyPage = bodyPage.PageNext;
}  
Console('number of pages is '  + counter);

The GetText() function is not working on BodyPage object. I also can not find a way to get TextRange of BodyPage in order to use GetTextForRange() property.

Do you know any way to check if page is empty or not?


Thanks.

 

Views

140

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jul 01, 2021 Jul 01, 2021

Here are a series of related functions that I use for this type of thing:

function pageIsEmpty (page) {
    
    var textFrame;
    
    textFrame = getTextFrame (page, "A");
    if (textFrame) {
        if (textFrameIsEmpty (textFrame) === true) {
            return true;
        }
    }

    return false;
}

function getTextFrame (page, flow) { 
    
    var frame, graphic;
    
    frame = page.PageFrame;
    graphic = frame.FirstGraphicInFrame;
    while (graphic.ObjectValid () === 1) {
    
...

Votes

Translate

Translate
Enthusiast ,
Jul 01, 2021 Jul 01, 2021

Copy link to clipboard

Copied

What do you mean with "empty"?

A page with no paragraph in it?

A page with one or more empty paragraphs in it?

A paragraph with no content i.e. table anchor, graphic anchor etc., text?

 

First of all you should read the chapter 4 "Frame Document Architecture" in the FDK Programmer Guide.

Here some hints:

A page contains a PageFrame

This PageFrame contains among others a TextFrame and this TextFrame contains the TextFrame.FirstPgf

 

So here you can start your search.

 

But I think it is much easier to go through your MainFlowInDoc to find all paragraphs with no content to delete them

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 01, 2021 Jul 01, 2021

Copy link to clipboard

Copied

LATEST

Here are a series of related functions that I use for this type of thing:

function pageIsEmpty (page) {
    
    var textFrame;
    
    textFrame = getTextFrame (page, "A");
    if (textFrame) {
        if (textFrameIsEmpty (textFrame) === true) {
            return true;
        }
    }

    return false;
}

function getTextFrame (page, flow) { 
    
    var frame, graphic;
    
    frame = page.PageFrame;
    graphic = frame.FirstGraphicInFrame;
    while (graphic.ObjectValid () === 1) {
        if (graphic.constructor.name === "TextFrame") {
            if (graphic.Flow.Name === flow) {
                return graphic;
            }
        }
        graphic = graphic.NextGraphicInFrame;
    }
}

function textFrameIsEmpty (textFrame) {
    
    if (textFrame.LastPgf.ObjectValid () === 1) {
        return false;
    } 
    else if (textFrame.LastCell.ObjectValid () === 1) {
        return false;
    } 
    else if (textFrame.LastAFrame.ObjectValid () === 1) {
        return false;
    } 
    else if (textFrame.LastFn.ObjectValid () === 1) {
        return false;
    }
    else {
        return true;
    }
}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines