Search code examples
javascriptadobe-indesign

InDesign Text Modification Script Skips Paragraphs


The following InDesign (Java)script does not change the text content and formatting of all paragraphs:-

for (var j = 0; j < app.activeDocument.stories.length; j++) {    
    for (var k = 0; k < app.activeDocument.stories.item(j).paragraphs.length; k++) {
        var myText = app.activeDocument.stories.item(j).paragraphs.item(k);
        myText.contents = C2Unic(myText.contents, myText.appliedFont.fontFamily);
        myText.appliedFont = app.fonts.item("Mangal");
        myText.pointSize = myText.pointSize*0.878;
        myText.composer="Adobe World-Ready Paragraph Composer";
    }
}

In the image below note the content with pink background. All those have source formatting. What is happening?

enter image description here


Solution

  • This might not be the solution, but sometimes it helps to loop backwards through paragraphs when you are modifying contents.

    for (var j = 0; j < app.activeDocument.stories.length; j++) {    
        for (var k = app.activeDocument.stories.item(j).paragraphs.length; k--; ) {
            var myText = app.activeDocument.stories.item(j).paragraphs.item(k);
            myText.contents = C2Unic(myText.contents, myText.appliedFont.fontFamily);
            myText.appliedFont = app.fonts.item("Mangal");
            myText.pointSize = myText.pointSize*0.878;
            myText.composer="Adobe World-Ready Paragraph Composer";
        }
    }