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

widows orphan line script

Participant ,
May 16, 2014 May 16, 2014

Hi,

I want to find the 'widows & orphan' lines in my active document, if its (window orphan) appeared, I need the log report. Is this possible by script.

by

hasvi

TOPICS
Scripting
2.4K
Translate
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

Enthusiast , May 19, 2014 May 19, 2014

Hi Hasvi,

Here is the modified one. If this fits your requirement then mark Jarek's answer is correct.

var reportwidow = "Following pages have widow line \r\r", reportorphan = "Following pages have orphan line \r\r";

var firstParas = app.activeDocument.pages.everyItem().textFrames.everyItem().textColumns.everyItem().paragraphs[0].getElements(); 

var lastParas =  app.activeDocument.pages.everyItem().textFrames.everyItem().textColumns.everyItem().paragraphs[-1].getElements();

for(var i=0;i<firstParas.

...
Translate
Enthusiast ,
May 17, 2014 May 17, 2014

Hi Hasvi,

Use the below code to get the widow and orphan report.

var pages = app.activeDocument.pages;

var reportwidow = "Following pages have widow line \r\r", reportorphan = "Following pages have orphan line \r\r", last, lastbutone, first, second;

for(var i=0;i<pages.length;i++)

{

    try{

        last = pages.textFrames[0].paragraphs[-1].lines[-1].parentTextFrames[0].parentPage.name;

        lastbutone = pages.textFrames[0].paragraphs[-1].lines[-2].parentTextFrames[0].parentPage.name;

        first = pages.textFrames[0].paragraphs[-1].lines[0].parentTextFrames[0].parentPage.name;

        second = pages.textFrames[0].paragraphs[-1].lines[1].parentTextFrames[0].parentPage.name;

    }

    catch(e){}

    if(last !=lastbutone)

    {

            reportwidow += last +", ";

        }

    if(first !=second)

    {

            reportorphan += first + ", ";

        }

}

alert(reportwidow);

alert(reportorphan);

Regards,

Chinna

Translate
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
Mentor ,
May 17, 2014 May 17, 2014

Hi,

@Chinna,

What about more textFrames on one page and more columns in a specific textFrame?

I think the code should compare each textColumns:

var

     firstParas = app.activeDocument.pages.everyItem().textFrames.everyItem().textColumns.everyItem().paragraphs[0].getElements(),

     lastParas =  app.activeDocument.pages.everyItem().textFrames.everyItem().textColumns.everyItem().paragraphs[-1].getElements(),

     len = firstParas.length, cnt = -1,

     widRep = "", orpRep = "";

while (++cnt < len)

  if (firstParas[cnt].lines[-1].textColumns[0] != firstParas[cnt].lines[-2].textColumns[0])

  widRep += "Page: " + firstParas[cnt].lines[-1].parentTextFrames[0].parentPage.name +

            "\tcheck the line: " + firstParas[cnt].lines[-1].contents;

len = lastParas.length;

cnt = -1;

while (++cnt < len)

  if (lastParas[cnt].lines[0].textColumns[0] != lastParas[cnt].lines[1].textColumns[0])

  orpRep += "\rPage: " + lastParas[cnt].lines[0].parentTextFrames[0].parentPage.name +

            "\tcheck the line: " + lastParas[cnt].lines[0].contents;

if (orpRep.length == 0) orpRep = "\r\tnot found";

if (widRep.length == 0) widRep = "\r\tnot found";

alert ("Orphans:" + orpRep + "\rWidows:\r" + widRep);

Jarek

Translate
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
Participant ,
May 17, 2014 May 17, 2014

Hi thanks for your valuable answer

Sent from Yahoo Mail on Android

Translate
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
Enthusiast ,
May 18, 2014 May 18, 2014

Thanks Jarek

Translate
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
Participant ,
May 19, 2014 May 19, 2014

Hi,

I try your script, but it shows error 'Object is invalid', on line 8, can you help me for this.

by

hasvi

Translate
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
Mentor ,
May 19, 2014 May 19, 2014

Hi,

Yes. Sorry. This error can be thrown when 1-liner comes or text frame is overflown.

So modify both if statement conditions alike:

...

if (firstParas[cnt] &&

    firstParas[cnt].lines.length > 1 &&

    firstParas[cnt].lines[-1].textColumns[0] != firstParas[cnt].lines[-2].textColumns[0]);

...

Jarek

Translate
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
Participant ,
May 19, 2014 May 19, 2014

Thanks Jarek

Translate
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
Participant ,
May 19, 2014 May 19, 2014

Hi Chinna,

I modify your script slightly, I have added 1st 2-lines for condition, that is my paragraph line must be greater than 1 line (myPara > 1), because it shows report for single line also, that's why I write this. But its shows the error on 1st line, can you help me?

var myPara=app.activeDocument.pages.textFrames[0].paragraphs[0].lines.length;

if (myPara > 1)

{

var pages = app.activeDocument.pages;

var reportwidow = "Following pages have widow line \r\r", reportorphan = "Following pages have orphan line \r\r", last, lastbutone, first, second;

for(var i=0;i<pages.length;i++)

{

    try{

        last = pages.textFrames[0].paragraphs[-1].lines[-1].parentTextFrames[0].parentPage.name;

        lastbutone = pages.textFrames[0].paragraphs[-1].lines[-2].parentTextFrames[0].parentPage.name;

        first = pages.textFrames[0].paragraphs[-1].lines[0].parentTextFrames[0].parentPage.name;

        second = pages.textFrames[0].paragraphs[-1].lines[1].parentTextFrames[0].parentPage.name;

    }

    catch(e){}

    if(last !=lastbutone)

    {

            reportwidow += last +", ";

        }

    if(first !=second)

    {

            reportorphan += first + ", ";

        }

}

var w=app.activeDocument;

var myTextFile = new File("~/Desktop/widow orphan.csv")

myTextFile.open("w")

myTextFile.write("\nreportwidow:")

myTextFile.write(reportwidow)

myTextFile.write("\n\nreportorphan:")

myTextFile.write(reportorphan)

myTextFile.close();

}

by

hasvi

Translate
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
Enthusiast ,
May 19, 2014 May 19, 2014

Hi Hasvi,

Here is the modified one. If this fits your requirement then mark Jarek's answer is correct.

var reportwidow = "Following pages have widow line \r\r", reportorphan = "Following pages have orphan line \r\r";

var firstParas = app.activeDocument.pages.everyItem().textFrames.everyItem().textColumns.everyItem().paragraphs[0].getElements(); 

var lastParas =  app.activeDocument.pages.everyItem().textFrames.everyItem().textColumns.everyItem().paragraphs[-1].getElements();

for(var i=0;i<firstParas.length;i++)

{

    try{

        var fline1 = firstParas.lines[-1].textColumns[0];

        var fline2 = firstParas.lines[-2].textColumns[0];

    }

    catch(e){}

    if(firstParas.lines.length>=2)

    {

        if(fline1 !=fline2)

        {

            reportwidow += firstParas.lines[-1].parentTextFrames[0].parentPage.name +", ";

        }

    }

}

for(var i=0;i<lastParas.length;i++)

{

    try{

        var Lline1 =lastParas.lines[0].textColumns[0];

        var Lline2 = lastParas.lines[1].textColumns[0];

    }

    catch(e){}

    if(lastParas.lines.length>=2)

    {

        if(Lline1 !=Lline2)

        {

            reportorphan += lastParas.lines[0].parentTextFrames[0].parentPage.name+", ";

        }

    }

}

var w=app.activeDocument;

var myTextFile = new File("~/Desktop/widow orphan.csv")

myTextFile.open("w")

myTextFile.write("\nreportwidow:")

myTextFile.write(reportwidow)

myTextFile.write("\n\nreportorphan:")

myTextFile.write(reportorphan)

myTextFile.close();

Regards,

Chinna

Translate
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
Participant ,
May 19, 2014 May 19, 2014
LATEST

Thank you chinna

Translate
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