Need script for Widow/Orphan control
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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;
}
}
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
I gave it a try and it worked great until it hit some nested Seqlists. I should have specified that we have nested Seqlists because most DTDs I've worked with (e.g., 38784) don't allow that. So what ended up happening was the Keep With Previous setting was applied to all list items within the nested lists. Are there some adjustments I could make to this script to compensate for this? Thanks again!
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.

