4 Replies Latest reply on Dec 26, 2012 12:53 AM by Xiarea

    Problem with script on Acrobat X Pro Mac OS

    Xiarea

      Hello,

       

      I got sevral time a "syntax error", a mising ')' or '}' or unterminated commet into my javaScript, in script that were actually perfectly correct.

       

      Turns out that the exact same script typed on Acrobat X on Windows, then opened on Mac OS would cause the same kind of error (usually, like this:

       

      line 58 : SyntaxError: unterminated comment

      57:.

       

      )

       

      I've noticed that if I shorten the code a bit (removing comments for exemple, or spaces between code blocks), it can solve the problem.

       

      Now I'd like to keep my code readable, so is there a solution to solve this problem?

       

      (I tried to uninstall/reinstall => nothing change)

       

      Also, if I try to edit all JavaScript scripts at once, oppening the file isn't a problem, I can edit everything I want. But Once I'm done, when I close teh editor, Acrobat will freeze, letting me no choice but kill the app. I don't know if this two problems are caused by the same thing...

        • 1. Re: Problem with script on Acrobat X Pro Mac OS
          try67 MVP & Adobe Community Professional

          Can you share the code (or the file) that was producing the error?

          • 2. Re: Problem with script on Acrobat X Pro Mac OS
            Xiarea Level 1

            Basically, it's any code. but I sure can paste the exemple I've been using here :

             

            // Met à jour les required sur les champs de la ligne si un element est saisi

            function champRequisLigne(element)

            {

                var regEntiers = /\d+/;

                var numLigne = regEntiers.exec(element.name);

                console.println('numero de la ligne à vérifier :'+numLigne+'\n');

                var chpDate = this.getField("date"+numLigne);

                var chpLibelle = this.getField("libelle"+numLigne);

                var chpSncf = this.getField("sncf"+numLigne);

                var chpKms = this.getField("kms"+numLigne);

                var chpHotel = this.getField("hotelrestottc"+numLigne);

                var chpDivers = this.getField("diversttc"+numLigne);

                var chpNature = this.getField("nature"+numLigne);

                var chpImputation = this.getField("imputation"+numLigne);

                var chpTva = this.getField("tva"+numLigne);

                var visaCompta = (this.getField("module").value == "NOTEDEFRAIS.visaCompta");

                if(ligneVide(numLigne))

                {

                    console.println('suppression des required sur la ligne '+numLigne+'\n:');

                    //plus rien n'est obligatoire sur cette ligne.

                    chpDate.required=false;

                    console.println(chpDate.name+' : OK\n');

                    chpLibelle.required=false;

                    console.println(chpLibelle.name+' : OK\n');

                    chpSncf.required=false;

                    console.println(chpSncf.name+' : OK\n');

                    chpKms.required=false;

                    console.println(chpKms.name+' : OK\n');

                    chpHotel.required=false;

                    console.println(chpHotel.name+' : OK\n');

                    chpDivers.required=false;

                    console.println(chpDivers.name+' : OK\n');

                    chpNature.required=false;

                    console.println(chpNature.name+' : OK\n');

                    chpImputation.required=false;

                    console.println(chpImputation.name+' : OK\n');

                    chpTva.required=false;

                    console.println(chpTva.name+' : OK\n');

                }

                else

                {

                    console.println('La ligne pas vide\n:');

                    if(visaCompta)

                        chpTva.required=true;

                    chpDate.required=true;

                    chpLibelle.required=true;

                    if(chpSncf.value||chpKms.value||chpHotel.value||chpDivers.value)

                    {

                        chpSncf.required=false;chpKms.required=false;chpHotel.required=false;chpDivers.required=f alse;

                        if(chpDivers.value)

                        {

                            chpNature.required=true;

                            if(visaCompta)

                                chpImputation.required=true;

                        }

                    }

                    /*Test avec un commentaire

                    Le but est d'avoir tellement

                    de commentaire que le code d'étale sur plus de 62 lignes

                    pour savoir si Acrobat ca accepter ce code

                    ou s'il renverra une erreur de type "syntax error"

                    Ensuite,j'insérerai le même commentaire depuis la version

                    windows d'acrobat 10 (la même version que celle utilisée en

                    ce moment sous Mac.

                   

                    Si les résultats défèrent, il faudra peut-être réinstaller

                    acrobat sur mon poste...*/

                }

            }

             

            Here the error is caused by the first line of the comment : /*Test avec un commentaire (in French, but I guess it doesn't really matter)

            • 3. Re: Problem with script on Acrobat X Pro Mac OS
              gkaiseril MVP & Adobe Community Professional

              Has your script ever worked?

               

              It looks like this is a document level script.

               

              Have you tried simplifying the script and only running a couple of lines at a time until you find  the error?

               

              If you are using hierarchical field names, then you need a dot, ".", between levels.

               

              A line like:

               

                var chpDate = this.getField("date"+numLigne);

               

              Should read:

               

                var chpDate = this.getField("date" + "." + numLigne);

               

              and so on.

               

              I would also check you pairs of "{"  and "}".  You might be missing a closing "}" somewhere.

               

              You might find when you have more than one level with only a numeric value, you are not getting the last level with your script.

               

              Adding comments for the end of loops and if then else statements could help. I also add a return statement at the end of a function.

               

              Additional comments and more fuller logical statements might help others understand your code.

               

              There appears to be some other functions being called and  I do not see the code.

               

              You might consider using the "select" statement and eliminate the complex "if then else if then" statements

              • 4. Re: Problem with script on Acrobat X Pro Mac OS
                Xiarea Level 1

                Yes it is a Document level script. Yes, it worked (it actually still does).

                It's not hierarchical fields, just fields having the same name plus a number (I didn't make the PDF file myself, I didn't chose...).

                It seems that if I click "I don't want to correct the mistake" (or I don't know what's the exact text in english version), Acrobat will still accept the code as it and include it.

                Resulting script works fine, but now I never know when there's actually a mistake in the code or when it's Acrobat making a joke.

                 

                My first guess was that the problem comes from my acrobat, but since the problem keeps going on after I've uninstalled it and put it back, I am clueless...

                 

                I had add a lot of comment (I basically start coding by placing comments about what I'll do, and how I'll do so) I had to remove them all in order to get rid of the error message (as I explained in my first post) I know it's a pain to read, and that's one of the reason why I want to solve this problem.

                It's really weird. I mean, of course, I tried to run its of the code to find out where the error is, but I never found out. The only result I came with is that if I remove enough comments (and ONLY comments) so the code gets shorter, there's no more error detected. That's why I think the error doesn't come from the script... I don't know what mechanism are used by Acrobat to include the Javascript in the document, but maybe it uses some file on my system that got corrupte for some reason?

                 

                 

                Still, can you tell me more about the "select" statement?