7 Replies Latest reply on Dec 15, 2014 8:54 AM by gkaiseril

    Error message: trim is not a function

    syswizardx Level 1

      I cannot get the standard string Trim() method to work in Acro Pro 11.

      What's up with that ?

      Any workarounds ?

        • 1. Re: Error message: trim is not a function
          George_Johnson MVP & Adobe Community Professional

          The trim string method was introduced with JavaScript 1.8.1. Acrobat 10/11 is documented as supporting 1.8, which I assume means 1.8.0. It's easy enough to create your own trim function, which will also work with pre-10 versions of Acrobat/Reader.

          • 2. Re: Error message: trim is not a function
            syswizardx Level 1

            George - Thanks for reminding me how primitive the script environment is with Acrobat.

            Trim was in VBA over a decade ago. I can't believe I have to write my own primitive methods.

            When, oh when, is Adobe going to rewrite the debugger and javascript interface ?

            After my 6 months of experience, It's actually laughable at this stage of the game.

            • 3. Re: Error message: trim is not a function
              gkaiseril MVP & Adobe Community Professional

              Actually if one looks at the trim method for JavaScript, there is a script provided that can be added to a PDF as a document level script and it will create trim prototype for string type objects if it is not present in the JavaScript being used by the form.


              This is the provided script from the MDN JavaScript reference for a right trim:


              if (!String.prototype.trim) {
                (function() {
                 // Make sure we trim BOM and NBSP
                  var rtrim = /^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g;
                  String.prototype.trim = function() {
                    return this.replace(rtrim, '');


              You can change the code for trim and ltrim functions.

              What is wrong with primitive? The C language started out very primitive but because one can easily add functions written in C using very primitive operators a newer more powerful version is created. In fact the C language is ported across various computers and Operating Systems by editing what is considered a small assembler program that will create the object code for the target system and then one copies the text code for the more advanced features in the C language and creates the production C version.

              • 4. Re: Error message: trim is not a function
                try67 MVP & Adobe Community Professional

                What does it have to do with Adobe? It's a feature that is missing from

                JavaScript, and one that takes about 2 seconds to implement, so what's the



                On Fri, Dec 12, 2014 at 12:41 PM, syswizardx <forums_noreply@adobe.com>

                • 5. Re: Error message: trim is not a function
                  syswizardx Level 1

                  Well, for one thing that rtrim statement sure could use an explanation. Is that a grep string or what ?

                  • 6. Re: Error message: trim is not a function
                    Test Screen Name Most Valuable Participant

                    I don't think you can expect comments to explain what each syntax feature is: this is a regular expression (which is the type of value also used by grep); you could also check this by looking at the definition of the replace method and what it takes as parameters .  The comment does explain what it does, and removing BOM and NBSP seems worthwhile (though the comment does not note it also removes spaces; we have to deduce that by the context). And the code is indeed from the "MDN JavaScript reference", a detailed reference not an introduction. But you don't need to understand it; it's available to you if you want its functionality.


                    If you don't like JavaScript that's understandable; I detest it myself. But we are stuck with it, and Adobe had good reasons for choosing an industry standard language; they are to be praised I think for not making up a new one. And VBA, being a Microsoft invention would not be suitable for portability. (This argument would be stronger if Adobe troubled to fully implement JavaScript on all devices, but there you go).

                    • 7. Re: Error message: trim is not a function
                      gkaiseril MVP & Adobe Community Professional

                      RegExp is a very common object type across many programs including grep, text processors, web scripting, and word processors to name a few types. There are plenty of sites on the web and books that deal with the RegExp expression.


                      You could also avoid using the RegExp




                      return rtrim(ltrim(s));



                      function ltrim(s)


                      var l=0;

                      while(l < s.length && s[l] == ' ')

                      { l++; }

                      return s.substring(l, s.length);



                      function rtrim(s)


                      var r=s.length -1;

                      while(r > 0 && s[r] == ' ')

                      { r-=1; }

                      return s.substring(0, r+1);