31 Replies Latest reply on Feb 3, 2015 10:30 AM by lindaeliseruble

    doc is not defined

    lindaeliseruble Level 1


      Hello,

       

      I am submitting a string of numbers delimited with commas from a form to be utilized by a JavaScript function.

       

      Here is the string of number I am submitting:

      7.4%,0.1%,0.4%,9.7%,53.1%,0.5%,15.5%,4.8%,1.6%,5.7%,1.0%

       

       

      Here is the function:

      function searchArray(doc, arrStr, startPage, endPage) {

      var arr = arrStr.replace(/\s/g,"").split(",");

      if (startPage==-1) startPage = 0;

      if (endPage==-1) endPage = doc.numPages-1;

      var results = [];

      for (var i in arr) results.push(false);

       

      pagesLoop:

      for (var p=startPage; p<=endPage; p++) {

        var numWords = doc.getPageNumWords(p);

        for (var i=0; i<numWords; i++) {

         var word = trim2(doc.getPageNthWord(p,i,false));

         var matchIndex = arr.indexOf(word);

         if (matchIndex!=-1) {

          if (results[matchIndex]==false) {

           results[matchIndex] = true;

           var allFound = true;

           for (var j in results) {

            if (results[j]==false) {

             allFound = false;

             break;

            }

           }

           if (allFound) break pagesLoop;

          }

         }

        }

      }

      return results;

       

      function trim2(s) {

        if (typeof s != "string") return s;

        return s.replace(/^\s+/,"").replace(/\s+$/,"");

      }

      }

       

       

       

      Here is the code that makes the button under "Add-On Tools":

      app.addToolButton({ cName: "LnchSrchPM", cLabel: "EMB-PM to BO Compare", cTooltext: "EMB-PM to BO Compare",

      cExec: "lnchSrchPM(false)", cEnable: "event.rc = (event.target!=null)"});

       

       

      Here is the function that takes the string of numbers and sends it to the searchArray function:

      function subSrchValPM() {

      var searchThis = " ";
      searchThis = this.getField(1).valueAsString;
      console.println(searchThis);

      }

       

       

      All I want to do at this point is to make the string of numbers that I am submitting appear in the debugging console.

       

      I can't seem to do that.

       

       

      I get the following error message:

       

      doc is not defined

      25:AcroForm:SubmitButton:Annot1:MouseUp:Action1Exception in line 25 of function subSrchValPM, script 0

       

       

       

      Line 25 is the following:

      searchThis = this.getField(1).valueAsString;


       

      Can someone tell me what I am doing wrong?

       

      Thanks!

       

      Linda

        • 1. Re: doc is not defined
          Bernd Alheit Adobe Community Professional & MVP

          As parameter of this.getField( ) you must use a field name not a number.

          • 2. Re: Re: doc is not defined
            lindaeliseruble Level 1

            I added quotes around the number "1" to make the number one a string (name of field)

             

            searchThis = this.getField("1").valueAsString;

             

            And I still got:

            doc is not defined

             

             

            What should I do now?

             

            Thanks

             

            Linda

            • 3. Re: doc is not defined
              Bernd Alheit Adobe Community Professional & MVP

              Where did you call the function subSrchValPM?

              • 4. Re: doc is not defined
                lindaeliseruble Level 1

                I Called the function subSrchValPM by clicking on the button in the form.

                • 5. Re: doc is not defined
                  gkaiseril MVP & Adobe Community Professional

                  I see no call toe the "searchArray" function in the posted code.

                   

                  When one uses a PDF doc object within a document or folder level function the PDF document object needs to be passed as a parameter.

                   

                  function subSrchValPM(oDoc) {

                  var searchThis = " ";
                  searchThis = Odoc.getField(String(1)).valueAsString;
                  console.println(searchThis);

                  }

                  • 6. Re: doc is not defined
                    Bernd Alheit Adobe Community Professional & MVP

                    I can't help without seeing the form and the whole code. You are posting only snippets.

                    • 7. Re: doc is not defined
                      lindaeliseruble Level 1

                      I was just taking it one step at a time.

                       

                      I wanted to see if I could get the string of numbers that I submitted to appear in the debugging console first.

                       

                      After I accomplish that, I will attempt to call the "searchArray"  Or is there something wrong by doing that?

                       

                      Thanks

                       

                      Linda

                      • 8. Re: doc is not defined
                        lindaeliseruble Level 1

                        Do you need to declare the oDoc as a variable somewhere first?

                        Also, do you need to put quotes around the number one?

                         

                        I changed the code to the below and now I don't even get my button under "Add-on Tools" to submit the form.

                         

                         

                        function subSrchValPM(oDoc) {

                        var searchThis = " ";
                        searchThis = Odoc.getField(String(1)).valueAsString;
                        console.println(searchThis);

                        }

                        • 9. Re: doc is not defined
                          gkaiseril MVP & Adobe Community Professional

                          The string:

                           

                          Odoc.getField(String(1)).valueAsString;

                           

                          Should be:

                           

                          oDoc.getField(String(1)).valueAsString;

                           

                          JavaScript is case sensitive.

                          • 10. Re: doc is not defined
                            lindaeliseruble Level 1

                            Already thought of that.  Changing it does not fix it.

                            • 11. Re: doc is not defined
                              lindaeliseruble Level 1

                              Hello

                               

                              I have gotten somewhere with the code.  Not very far, however.

                               

                               

                              I first tested a form with one text field and a button that calls the subSrchValPM() function of a folder level javascript file.

                              I pasted the following string of text into the form field"

                              7.4%,0.1%,0.4%,9.7%,53.1%,0.5%,15.5%,4.8%,1.6%,5.7%,1.0%

                              and clicked the submit button that calls the subSrchValPM() function.

                               

                              Here is the subSrchValPM() function:

                               

                              function subSrchValPM() {

                                  var searchThis = "";

                                  searchThis = this.getField(1).valueAsString;

                                  console.println(searchThis);

                              }

                               

                              It prints out the string of numbers in the debugging console.

                               

                              However......

                               

                              When I take out the "console.println(searchThis); " line

                              and replace it with this: "searchArray(this,searchThis,0,1);"

                               

                              I get the following error:

                               

                              TypeError: Invalid argument type.

                              Doc.getPageNumWords:187:Field SubmitButton:Mouse Up

                              ===> Parameter nPage.

                               

                               

                              However, when I run the following code in the debugging console:

                               

                               

                              var searchThis = "7.4%,0.1%,0.4%,9.7%,53.1%,0.5%,15.5%,4.8%,1.6%,5.7%,1.0%";

                              searchArray(this,searchThis,0,1);

                               

                               

                              I don't have a problem and get these results in the debugging console:

                               

                              true,true,true,true,true,true,true,true,true,true,true

                               

                              It prints out "true" whenever it takes a number from the string that was submitted and finds it in the two page document it is searching.

                               

                              So why does the searchArray function work when I test it in the console, but not when I test it in the folder level JavaScript file?

                               

                              What do I need to change to make it work in the folder level JavaScript file?

                               

                              Thanks

                               

                              Linda

                              • 12. Re: doc is not defined
                                Bernd Alheit Adobe Community Professional & MVP

                                Did you re-start Acrobat after changing the folder level Javascript file?

                                • 13. Re: doc is not defined
                                  lindaeliseruble Level 1

                                  Yes, I always restart Acrobat each time I make a change to the folder level JavaScript file.

                                   

                                  The thing is, the code works in the debugging console but does not work when it is in the folder level JavaScript file.

                                   

                                  The following code works in the debugging console:

                                  var searchThis = "7.4%,0.1%,0.4%,9.7%,53.1%,0.5%,15.5%,4.8%,1.6%,5.7%,1.0%";

                                  searchArray(this,searchThis,0,1);

                                   

                                  I tried changing "this" to "doc" hoping that would work but does not.

                                  Here is the error message again.

                                   

                                  TypeError: Invalid argument type.

                                  Doc.getPageNumWords:187:Field SubmitButton:Mouse Up

                                  ===> Parameter nPage.

                                   

                                  Why is it complaining about an invalid argument type?
                                  Why does it mention "Parameter nPage"?

                                   

                                   

                                   

                                   

                                   

                                  The function does not have a parameter nPage in it:

                                  function searchArray(doc, arrStr, startPage, endPage)

                                   

                                   

                                  Why does it work in the debugging console and not in the folder level file? What is the difference?

                                   

                                   

                                  Thanks

                                   

                                   

                                  Linda

                                  • 14. Re: doc is not defined
                                    Test Screen Name Most Valuable Participant

                                    I haven't looked closely at your code but your question seems to mix up YOUR parameters with those of build in methods.

                                     

                                    doc.getPageNthWord takes parameters nPage, nWord and bStrip, per the documentation.

                                    The message mentions doc.getPageNthWord.

                                     

                                    By understanding is that you should look at your call(s) to getPageNthWord and carefully check their parameter value(s). Perhaps add a line or two to report the values of parameters immediately before the call.

                                    • 15. Re: doc is not defined
                                      Bernd Alheit Adobe Community Professional & MVP

                                      lindaeliseruble wrote:

                                       

                                      Here is the error message again.

                                       

                                      TypeError: Invalid argument type.

                                      Doc.getPageNumWords:187:Field SubmitButton:Mouse Up

                                      ===> Parameter nPage.

                                       

                                      Why is it complaining about an invalid argument type?
                                      Why does it mention "Parameter nPage"?

                                      The method getPageNumWords uses the parameter nPage. Look at the Acrobat Javascript Reference.

                                      • 16. Re: doc is not defined
                                        gkaiseril MVP & Adobe Community Professional

                                        it lookks like you have a number of errors all over your code. If you use the JavaScript console to identify your your erroers you might be able to correct them The console shows the action where the error occured, the approximate line number, and type of error.

                                         

                                        JavaScript is not a compiled language, but a scritp and each line of code is reprocessed each time te code is processed and it stops as soon as an error occurs and all the following JavaScript no matter whre it is located is not executed.

                                         

                                        It would be helprul you shared your PDF form.

                                        • 17. Re: doc is not defined
                                          lindaeliseruble Level 1

                                          Hello

                                           

                                          I have gotten somewhere with the code.  Not very far, however.

                                           

                                           

                                          I first tested a form with one text field and a button that calls the subSrchValPM() function of a folder level javascript file.

                                          I pasted the following string of text into the form field"

                                          7.4%,0.1%,0.4%,9.7%,53.1%,0.5%,15.5%,4.8%,1.6%,5.7%,1.0%

                                          and clicked the submit button.

                                           

                                          Here is the subSrchValPM() function:

                                           

                                          function subSrchValPM() {

                                              var searchThis = "";

                                              searchThis = this.getField(1).valueAsString;

                                              console.println('"'+searchThis+'"');

                                          }

                                           

                                          It prints out the string of numbers in the debugging console.

                                           

                                          However......

                                           

                                          When I take out the "console.println('"'+searchThis+'"'); " line

                                          and replace it with this: "searchArray(this,searchThis,0,1); "

                                           

                                          I get the following error:

                                           

                                          TypeError: Invalid argument type.

                                          Doc.getPageNumWords:187:Field SubmitButton:Mouse Up

                                          ===> Parameter nPage.

                                           

                                           

                                          The error is on line 187:

                                          var numWords = doc.getPageNumWords(p);

                                           

                                           

                                          The full searchArray function has been mentioned in an earlier post.

                                           

                                           

                                           

                                          and replace it with this: "searchArray(this,searchThis,0,1); "

                                          • 18. Re: doc is not defined
                                            lindaeliseruble Level 1

                                            I have added the following three lines of code...

                                              console.println(p);

                                              console.println(i);

                                              console.println(word);

                                             

                                            right before this line to see what values I was getting.

                                              var word = trim3(doc.getPageNthWord(p,i,false));

                                             

                                             

                                            I got the following results in the debugging console:

                                             

                                             

                                            0
                                            0
                                            undefined
                                            0
                                            1
                                            EMB
                                            0
                                            2

                                            0
                                            3
                                            PM
                                            0
                                            4
                                            to
                                            0
                                            5
                                            B.
                                            0
                                            6
                                            O.
                                            0
                                            7
                                            Compare
                                            0
                                            8
                                            17
                                            0
                                            9
                                            18
                                            0
                                            10
                                            SUBMIT
                                            0
                                            11
                                            7.4%,
                                            0
                                            12
                                            0.1%,
                                            0
                                            13
                                            0.4%,
                                            0
                                            14
                                            9.7%,
                                            0
                                            15
                                            53.1%,
                                            0
                                            16
                                            0.5%,
                                            0
                                            17
                                            15.5%,
                                            0
                                            18
                                            4.8%,
                                            0
                                            19
                                            1.6%,
                                            0
                                            20
                                            5.7%,

                                            TypeError: Invalid argument type.
                                            Doc.getPageNumWords:188:Field SubmitButton:Mouse Up
                                            ===> Parameter nPage.

                                             

                                             

                                             

                                            I did notice that when submitted, the form does not go away and it looks like the script does not get to search the actual document.

                                             

                                            It appears that the script searches the form.  When I looked for the value of the variable "word", it was actually picking up the words on the form such as EMB, PM, to, B., O., Compare, SUBMIT,  and all the numbers in the text field of the form.

                                             

                                             

                                            Something is preventing the form from submitting properly and this is causing the script to not work.

                                             

                                             

                                            Please tell me how I can send you a copy of my form so that you can look at it.

                                             

                                             

                                            Thanks

                                             

                                             

                                             

                                            Linda

                                            • 19. Re: doc is not defined
                                              lindaeliseruble Level 1

                                              When I try to upload the PDF form, I get the following message:

                                               

                                              You are not allowed to create or update this content

                                               

                                               

                                              Do I need to be given permission to upload the form?

                                               

                                              Please let me know what I should do.

                                               

                                              Thanks

                                               

                                               

                                              Linda

                                              • 20. Re: doc is not defined
                                                Test Screen Name Most Valuable Participant

                                                Where are you trying to upload it? You cannot upload it to the forum, it only takes pictures. You can upload it to your own web site, to acrobat.com, or any other public file sharing site.

                                                • 21. Re: doc is not defined
                                                  lindaeliseruble Level 1

                                                  Thank you for letting me know how to share my files.

                                                   

                                                  Here is where you can access the form I created.

                                                   

                                                  http://www.printandpixel.com/Input%20Page11.pdf

                                                   

                                                   

                                                  Thanks

                                                   

                                                  Linda

                                                  • 22. Re: doc is not defined
                                                    Bernd Alheit Adobe Community Professional & MVP

                                                    After adding the function subSrchValPM I get no error.

                                                    function subSrchValPM() {

                                                    var searchThis = " ";
                                                    searchThis = this.getField(1).valueAsString;
                                                    console.println(searchThis);

                                                    }

                                                    • 23. Re: doc is not defined
                                                      lindaeliseruble Level 1

                                                      What results do you get in the debugging console?

                                                       

                                                      Do you get something like:

                                                      true, true, true, true, true, true, true, true, true

                                                       

                                                       

                                                      Does your form just stay open after you click the submit button?  Mine does and I think that is the problem.  The script searches the form and not the document it is supposed to be searching.

                                                       

                                                      I have uploaded the document that the script is supposed to be searching:

                                                      http://www.printandpixel.com/ARY-BO-PM2.pdf


                                                      Here is the string of numbers that you need to submit from the form:

                                                      7.4%,0.1%,0.4%,9.7%,53.1%,0.5%,15.5%,4.8%,1.6%,5.7%,1.0%

                                                       

                                                       

                                                       

                                                       

                                                      Thanks

                                                       

                                                       

                                                      Linda

                                                      • 24. Re: doc is not defined
                                                        Bernd Alheit Adobe Community Professional & MVP

                                                        The function displays only the text entered in the field.

                                                         

                                                        Where do you use second document?

                                                        • 25. Re: doc is not defined
                                                          lindaeliseruble Level 1

                                                          Hi,

                                                           

                                                          The second document that I gave you is the document to be searched.

                                                           

                                                          You would open that document in Adobe Reader.  Under "Extended" -> "Add-on Tools" you would have a button that when clicked would

                                                          bring up the form with the one field and submit button.

                                                           

                                                          when you paste the following numbers into the one text field:

                                                          7.4%,0.1%,0.4%,9.7%,53.1%,0.5%,15.5%,4.8%,1.6%,5.7%,1.0%

                                                           

                                                          and click the submit button, that will launch the subSrchValPM function below that is in a folder level script:

                                                           

                                                          function subSrchValPM() {

                                                          var searchThis = " ";
                                                          searchThis = this.getField(1).valueAsString;
                                                          //console.println(searchThis);

                                                          searchArray(this,searchThis,0,1);

                                                          }

                                                           

                                                           

                                                          That function accesses the searchArray function (also in the folder level script) mentioned earlier in this chain of posts.

                                                           

                                                           

                                                          Thanks

                                                           

                                                           

                                                          Linda

                                                          • 26. Re: doc is not defined
                                                            Bernd Alheit Adobe Community Professional & MVP

                                                            lindaeliseruble wrote:

                                                             

                                                            Hi,

                                                             

                                                            The second document that I gave you is the document to be searched.

                                                             

                                                            You would open that document in Adobe Reader.  Under "Extended" -> "Add-on Tools" you would have a button that when clicked would

                                                            bring up the form with the one field and submit button.

                                                            When I open the document in Adobe Reader I can't see "Extended".

                                                            • 27. Re: doc is not defined
                                                              lindaeliseruble Level 1

                                                              it depends on the version of Adobe Reader.  What version do you have?  Do you see a tab that says " tools"? Add- ons will be under that. If you have a folder level JavaScript button with the the code I provided in an earlier post you should get a button that will open the form.

                                                              • 28. Re: doc is not defined
                                                                Bernd Alheit Adobe Community Professional & MVP

                                                                I have the actual version of Adobe Reader. Under "Tools" there are the normal tools of Adobe Reader, no Add-on.

                                                                 

                                                                I don't have a folder level Javascript button.

                                                                • 29. Re: doc is not defined
                                                                  Test Screen Name Most Valuable Participant

                                                                  Looking over this, it seems extraordinarily complicated. Two PDFs - why? I've never seen anything like this. Is the first PDF just for providing a UI to a button - if so you should use the Dialog features of JavaScript.

                                                                  • 30. Re: doc is not defined
                                                                    Test Screen Name Most Valuable Participant

                                                                    Also, you seem to be relying on "this" as being set. But "this" is only valid in certain very specific contexts, per the documentation. Never use it in code run from a button unless the documentation gives it a meaning.

                                                                    • 31. Re: doc is not defined
                                                                      lindaeliseruble Level 1

                                                                      Yes, this problem has become too involved so I am going to put it aside for now.

                                                                       

                                                                      Thanks

                                                                       

                                                                       

                                                                      Linda