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.
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) {
...
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
Copy link to clipboard
Copied
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;
}
}