4 Replies Latest reply: Jul 2, 2013 9:15 AM by K.Daube RSS

    Getting text from footnotes

    K.Daube Community Member

      Dear all,

       

      Having managed to extract citations from ordinary paragraphs and table cells I now want to get it also from footnotes. See the complete script and test-doc (FN-11) doc here.

       

      I get the first footnote paragraph with its citation correctly.

      But my construct to get the next paragraph of the footnote obviously is wrong - there is no NextPgfInFn (or NextPgf) mentioned in the Scripting Guide, only FirstPgf and LastPgf. But it is possible to have multiple paragraphs in footnotes (see test-doc). And hence the function GetText fails for the 'second paragraph' in the footnote.

       

      function processFootnote (fn, doc) {
      // find citations in footnotes
          var fnText = "";
          var fnPara = fn.FirstPgf;
          
          while (fn.ObjectValid()) {
            fnText = (GetText(fnPara));
              alert (fnText);                    // the text of the cell
              var citations = GetTempCitations (fnText);
              var nCitations = citations.length;
              alert (nCitations + " Citations = " + citations); 
          fnPara = fnPara.NextPgfInFn;                                               // <-------------- this is not valid
          }
      } //--------------------------------------------------------------------------
      function GetText (textObj, doc) {
        // Gets the text from the text object.
        var text = "";
        // Get a list of the strings in the text object or text range.
        if (textObj.constructor.name !== "TextRange") {                        // <--------------- Undefined is not an object
          var textItems = textObj.GetText(Constants.FTI_String);
        } else {
          var textItems = doc.GetTextForRange(textObj, Constants.FTI_String);
        }
        // Concatenate the strings.
        for (var i = 0; i < textItems.len; i += 1) {
          text += (textItems[i].sdata);
        }
        return text; // Return the text
      } //--------------------------------------------------------------------------
      

       

      What would be a valid construct to get into all paragraphs of the footnote?

       

      And there the next question lures: does function processFootnote also handle table footnotes ?

       

      Thanks for Your help.

      Klaus Daube

        • 1. Re: Getting text from footnotes
          frameexpert Community Member

          Hi Klaus,

           

          Use NextPgfInFlow

           

          Rick

          • 2. Re: Getting text from footnotes
            K.Daube Community Member

            Thank You, Ric, that worked.

            However, i had to add a 'stop', because an endless number of empty footnotes were found.

            function processFootnote (fn, doc) {
            // find citations in footnotes
                 var fnText = "";
                 var fnPara = fn.FirstPgf;
                 
                 while (fn.ObjectValid()) {
                   fnText = (GetText(fnPara));
                   if (fnText == ""){ return; }       // <----------------- prevent runaway
                      alert (fnText);                    // the text of the footnote
                      var citations = GetTempCitations (fnText);
                      var nCitations = citations.length;
                      alert (nCitations + " Citations = " + citations); 
                fnPara = fnPara.NextPgfInFlow;
                 }
            } //--------------------------------------------------------------------------
            
            • 3. Re: Getting text from footnotes
              frameexpert Community Member

              Hi Klaus, The code in your function is not quite right. The way I understand it, you are using the processFootnote function to process a single footnote. If that is the case, then this line:

               

              while (fn.ObjectValid()) {
              

               

              is not correct. The fn object will always be valid and that is why you have a runaway loop. You need this instead:

               

              while (fnPara.ObjectValid()) {
              

               

              This code will be unnecessary:

               

              if (fnText == ""){ return; }
              

               

              Rick

              • 4. Re: Getting text from footnotes
                K.Daube Community Member

                Thanks Rick - this solved the problem.

                 

                Now I'm able to collect the citations in

                - ordinary paragraphs,

                - table cells

                - foot notes

                - table foot notes.

                For the purpose of my project I postpone looking into textframes in anchored frames and other constructs (something must be left for later enhancements...)