1 Reply Latest reply on Aug 10, 2017 7:18 PM by Sudha K

    Add tagged text mid paragraph

    T_Stevens Level 1

      I have a table of contents without the page numbers. I can't use the auto-TOC, so I'm trying to add the page numbers via script. The whole document is tagged, and I'm using those tags to find the page where each chapter starts. Now I just need to add the page number to the TOC reference. That's where I'm getting stuck.

       

      I figured the easiest way to do it would be to create a temporary tag and add that to the end of each TOC reference, then set the contents of the temp tag to the page number, then untag it. It almost works, but the tag is added after the hard return (so it appears on the beginning of the next line, like so:

      Screen Shot 2017-08-10 at 9.43.52 AM.png

       

      The script I have so far is this:

       

      function insertPageNumbers(tocItem, pageNum) {

          var tag1;

          tag1 = tocItem.xmlElements.add('TEMP');

          tag1.contents = pageNum;

      }

       

      The other idea I had was to add placeholder text (like 'xx' or something) first, then tag that text using a find, but that seems like it would be more cumbersome.

      Can anyone give me an idea of how to insert the tag before the hard return, or do I need to go a different route?