6 Replies Latest reply on Jul 15, 2013 1:05 PM by Test Screen Name

    PDF Forms & Text

    McFreely

      I've created a pdf fillable form and currently the document isn't performing quite right.  There are a few enhancements I'd like to implement; hopefully, "the experts" can help. 

       

      Please provide code for the following:

       

      1. Left-center text within a form field

       

      2. Text format set as Number with no decimal places, but will allow for additional characters (text) within the same form field

       

      3.  Text format set as Number that will hide decimal places for whole values like $45,000, but will show decimal places for values like $47,470.72

       

       

      Thanks

        • 1. Re: PDF Forms & Text
          mrfale67 Level 2

          Hi,

          double-click on the field, validate, custom-script. Then paste this:

           

          event.rc = true;

          var f = event.target;

          f.alignment = "left";

          var startValue = event.value;

          var takeDecNumString = startValue;

          takeDecNumString = takeDecNumString.replace(/[^0-9\.]/gi,'');

          var takeDecNum = parseFloat(takeDecNumString);

          var intCheck = isInt(takeDecNum);

          if (intCheck) {

                    takeDecNum = parseInt(takeDecNumString);

          }

          takeDecNum = numberWithCommas(takeDecNum);

          startValue = startValue.replace(/[^a-z]/gi,'');

          event.value = "$" + takeDecNum + " " + startValue;

          function isInt(n) {

             return typeof n === 'number' && n % 1 == 0;

          }

          function numberWithCommas(x) {

              return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");

          }

           

          credits:

          1) http://stackoverflow.com/questions/3885817/how-to-check-if-a-number-is-float-or-integer

          2) http://stackoverflow.com/questions/2901102/how-to-print-a-number-with-commas-as-thousands- separators-in-javascript

          and last but not the least our best friend:

          3) http://www.adobe.com/devnet/acrobat/javascript.html (JavaScript for Acrobat API)

          (you can find the perfect answer to your first question under Field properties-->alignment)

           

          PS: the proposed solution as it is now, is far from being perfect:

          --> try four decimal digits;

          --> try to add text before and after the number;

          -->...

          • 2. Re: PDF Forms & Text
            McFreely Level 1

            mrfale67,

             

            Thanks for your repsonse, but as you mentioned, "the proposed solution is far from perfect".  Actually, there's a minor issue I'm having with the code - the default value is showing as $Nan.  How can the code be modified to show the default value as an empty/blank text box?

            • 3. Re: PDF Forms & Text
              Test Screen Name Most Valuable Participant

              Not perfect, but surely a good starting point for your own programming...?

               

              NaN usually means the value is the result of dividing by zero. Add a test for that, once you've worked out where the problem is.

              • 4. Re: PDF Forms & Text
                try67 MVP & Adobe Community Professional

                NaN usually means the value is the result of dividing by zero.

                 

                Not in this case, as I don't see any divisons done anywhere in the code... NaN stands for "Not a Number". It can be the result of any mathematical operation involving a variable that isn't a number and can't be converted to one.

                 

                In this case, it's most likely caused by the parseFloat() method. If you pass to it a string that can't be converted into a number, it will return NaN.

                • 5. Re: PDF Forms & Text
                  McFreely Level 1

                  Test Screen Name,

                   

                  I am not-at-all well versed in Javascript program, so I wouldn't know where to begin to "add a test". 

                   

                  I've searched the internet for solutions to my issue(s), but as you can see, the topic of my issues are too specific to produce relevant responses.  That's why I'm here......

                   

                  Again, to all "experts", thanks in advance for your help and any coding suggestions are greatly appreciated!!!!!

                  • 6. Re: PDF Forms & Text
                    Test Screen Name Most Valuable Participant

                    I think you're saying, you want us to do your job for you. Well, good luck with that.