0 Replies Latest reply on Aug 22, 2016 6:12 AM by chrlsdrwn12

    [JS][CC] Get the first character on each page

    chrlsdrwn12 Level 1

      Hi scripters,


      We have an InDesign xml out workflow and one of the requirements is page break. The InDesign document has one story for the text and then with multiple images and tables which have wraps to push the main text flow. Now i've written something which does exactly what I intended:


      function pageAnchors(){
          writeLog('    Creating Page Anchors...');
          var myPages = myDoc.pages;
          var myTitlePagePara = myPages[0].textFrames[0].paragraphs[1];
          var myTitle1stChar;
          for(var i=0; i<myTitlePagePara.characters.length; i++) {
              if (myTitlePagePara.characters[i].contents.match(/^\w+$/)){
                  myTitle1stChar = myTitlePagePara.characters[i];
          var myTitleParentTag = myTitle1stChar.texts[0].associatedXMLElements[0];
          var myTitlePageAnchorTag = myTitleParentTag.xmlElements.add("xref", myTitle1stChar);
          writeLog('        tagged first page '+myPages[0].name);
          // alert(myTitle1stChar.contents);
          for(var i=1; i<myPages.length; i++) {
              // alert("page "+myPages[i].name);
              if (myPages[i].textFrames.length > 0){
                  var my1stChar;
                  var myFrame = myPages[i].textFrames[-1];
                  var myText = myFrame.texts[0];
                      var myLine = myText.lines[0];
                      for (var c=0; c<myLine.characters.length; c++) {
                          try {
                              if (myLine.characters[c].contents.match(/^\w+$/)){
                                  my1stChar = myLine.characters[c];
                          catch(err) {
                              writeLog('        error on page '+myPages[i].name+': '+err.message);
                      var parentTag = my1stChar.texts[0].associatedXMLElements[0];
                      var pageAnchorTag = parentTag.xmlElements.add("xref", my1stChar);
                      writeLog('        tagged page '+myPages[i].name);
                      writeLog('        Page '+myPages[i].name+' has an error: '+err.message);           
                  writeLog('        Page '+myPages[i].name+' has no text frame.');           
          writeLog('    Page anchors were created!');


      My problem is I don't know how do I get to the image frames and tables (sometimes they are continued) if there are any on the page?


      I appreciate any idea. I'm not very in coding but i can code enough for my needs so even a logic would be very appreciated.