Delete only EMPTY Trailing Paragraphs
@frameexpert - I'm not sure if it was supplied by you or someone else, but I have a script that deletes empty paragraphs at the end of a document, but it deletes the paragraph if it doesn't contain text (i.e. it will delete paragraphs with an anchor for an anchored frame or with a table anchor also.) I need to revise the script to ONLY delete empty paragraphs.
As a workaround, I've told our writers to add a couple of spaces before or after the marker, which solves the problem, but it's not a permanent solution.
This is the script:
var doc = app.ActiveDoc;
DeleteBlankParagraphs(doc);
function DeleteBlankParagraphs(doc)
{
var pgf;
// Get the last paragraph in the main flow.
pgf = GetLastParagraph(doc);
// Loop backwards through the empty paragraphs.
while (pgf.ObjectValid () === 1)
{
// If the paragraph is empty, delete it.
if (getPgfText (pgf) === "")
{
pgf.Delete ();
}
else
{ // Otherwise, exit the loop.
break;
}
// pgf = GetLastParagraph(doc);
}
}
function GetLastParagraph(doc)
{
var pgf
// Loop through the paragraphs in the document's main flow.
pgf = doc.MainFlowInDoc.FirstTextFrameInFlow.FirstPgf;
while (pgf.ObjectValid() === 1)
{
// text = getPgfText(pgf, doc);
// Console (text);
if (pgf.NextPgfInFlow.ObjectValid()===0)
{
return pgf;
}
else
{
pgf=pgf.NextPgfInFlow;
}
}
} // End GetLastParagraph
function getPgfText(pgf)
{
var text, textList, count, i;
textList = pgf.GetText (Constants.FTI_String);
text = "";
count = textList.length;
for (i = 0; i < count; i += 1)
{
text += (textList[i].sdata);
}
return text;
} //end getPgfTextThank you in advance!!!