Skip to main content
Inspiring
August 15, 2024
Question

Need script for Widow/Orphan control

  • August 15, 2024
  • 2 replies
  • 692 views

Hello. I need a script for structured documents that can find the first and last item element in a sequential list and set them to Keep with Previous. I know this can be controlled through the EDD, but our templates are provided by our customer and we are unfortunately prohibited from editing them. Getting them to fix it is like getting blood out of a turnip. My team wastes a lot of time trying to find widows and orphans and when one slips through, it typically means republishing to PDF from scratch. I need this to be an automated process. Does anyone know of a script that could perform this function for me? If this has already been answered in another thread, I'd be happy to be redirected there. Thanks in advance. 
Matt

This topic has been closed for replies.

2 replies

frameexpert
Community Expert
Community Expert
August 19, 2024

Yatani's script is an elegant solution; however, I might be tempted to choose Structure > EDD > Export Element Catalog as EDD. Then set the first and last paragraph rules to keep with next and keep with previous, respectively, for the sequential list element. You could use File > Import > Element Definitions to import this "special" EDD when you are doing your PDF publishing.

MattS156Author
Inspiring
September 19, 2024

Thanks for the suggestion. I'm going to try the script first only because my organization is not permitted to alter the EDD provided by our customer. Personally, I'd rather do it this way and just not tell anyone outside of my group. 

Participating Frequently
August 19, 2024

Hi,
Manually overriding paragraph formatting should not be used in structured documents, as it can lead to confusion in future revisions.
However, if you must do so, the following script might help:

#target framemaker
/*
    Finds the first and last elements in a sequential list and overrides paragraph formatting
*/

var doc = app.ActiveDoc;
var elements = doc.MainFlowInDoc.GetText (Constants.FTI_ElementBegin);

for (var i=0;i<elements.length;i++){
    // Enter the name of a sequential list element defined in your EDD
	if (elements[i].obj.ElementDef.Name == "Seqlist"){
        f_changePgfProps (elements[i].obj.FirstChildElement);
        f_changePgfProps (elements[i].obj.LastChildElement);
    }
}

function f_changePgfProps (ele){
    // Modify the script as needed
    var childEles = ele.GetText (Constants.FTI_ElementBegin);
    for (var i=1;i<childEles.length;i++){
        childEles[i].obj.TextRange.beg.obj.KeepWithPrev = true;
    }
}
MattS156Author
Inspiring
September 19, 2024

Thank you very much for this script. I'm going to try it right away. I understand what you're saying about paragraph overrides possibly leading to confusion, but in this case I think it will work well. I developed a FOSI for a program that used Arbortext for the authoring and set the first and last item elements to keep with previous and it worked beautifully. We never had any widow/orphan issues in the 10 or so years since. I can't wait to give your script a try.