8 Replies Latest reply: Aug 18, 2014 1:18 PM by shawninvancouver RSS

    Dynamically auto-center text fields?

    shawninvancouver Community Member

      Hello all,

       

      I have an interesting dilemma. I am attempting to create a business card form when our office manager only needs to fill in four fields, save the PDF, and send to the printer.

       

      With the example text (attached image) and similar length text, it works out well with the two lines being centered/symmetrical on the card. However, whenever there are longer names or longer titles, the whole line is no longer centered.

       

      Question: Is there a way to wrap the two text fields (while one is right justified and the other is left justified) and automatically center both fields as determined by the text length?

       

      Bonus question

       

      Question 2:

      There are two other business card styles: 1) only an email address; 2) two phone numbers and email address.

      I don't know if I can add conditional fields (can I?) where the office manager can switch on/off the other card fields (which involves changing the position of the 2nd line fields). Is Acrobat sophisticated enough to allow that or must I create three business card templates?

       

      Thank you so much!

      Shawn

      PDF Query.png

        • 1. Re: Dynamically auto-center text fields?
          George Johnson CommunityMVP

          How about using a single test field that's centered and prompting the user (app.response or custom dialog) for the values that would normally go in the Name and Title field, and include the pipe character in the text field between the two values? You'd have to use a field formatted for rich text if you want to use different font styles and colors for the two values and set the field value using two spans. All of this would involve JavaScript.

           

          You can implement #2 with a single page, using a button to display a different background depending on which type is selected, and having three sets of fields. JavaScript can be used to show/hide the relevant set and hide the others. This is somewhat complicated to spell out exactly how to do this in the forum, but it's possible. Whether it's worth the development time is another question.

          • 2. Re: Dynamically auto-center text fields?
            shawninvancouver Community Member

            Thanks George,

             

            Just focusing on the first question... is that really the only way to accomplish this goal (i.e. using a javascript)?

             

            But either solution is clearly not something I can tackle, at this time. I have never worked with javascript within Acrobat and this is a side-project (volunteer).

            • 3. Re: Dynamically auto-center text fields?
              George Johnson CommunityMVP

              It's the only way (short of a custom plug-in) to do it all automatically. If you simply create a text field that is set up for rich text formatting, the user can change the font, style, and color of the Name text and the Title text.

              • 4. Re: Dynamically auto-center text fields?
                shawninvancouver Community Member

                Hi George,

                 

                George Johnson wrote:

                 

                the user can change the font, style, and color of the Name text and the Title text.

                 

                That is exactly what I want to avoid.

                 

                I have never worked much beyond creating basic forms in Acrobat and I am quite underwhelmed with it's inability to accomplish such a simple task, without a whole lot of extra work. Still, I admit that I think I might be missing some key facts/knowledge.

                 

                I experimented with creating a single field and assigning a centered attribute to it. In the text field properties > Options tab > Centered and Rich Text Formatting > Calculate tab > Custom Calculation Script:

                 

                var ObjectName = "line 1";

                var JoinArrayStyle = new Array();

                 

                JoinArrayStyle[0] = new Object();

                JoinArrayStyle[0].text = " John Smith ";

                JoinArrayStyle[0].fontstyle = bold;

                JoinArrayStyle[0].textSize = 10;

                JoinArrayStyle[0].textColor = color.black;

                 

                JoinArrayStyle[1] = new Object();

                JoinArrayStyle[1].text = " | ";

                JoinArrayStyle[1].fontWeight = 900;

                JoinArrayStyle[1].textSize = 10;

                JoinArrayStyle[1].textColor = color.black;

                 

                JoinArrayStyle[2] = new Object();

                JoinArrayStyle[2].text = "Senior Software Engineer";

                JoinArrayStyle[2].fontstyle = italic;

                JoinArrayStyle[2].textSize = 9;

                JoinArrayStyle[2].textColor = color.red;

                 

                this.getField(ObjectName).richValue = JoinArrayStyle;

                 

                When I first tested this, it appeared to sort of work but now it is doing nothing. I am not even certain that "fontstyle" is valid...

                 

                Even if I can get the above working, it isn't ideal because it would be too easy to erase the rich text formatting. It made more sense to have two independent text fields, grouped together and centered together. 

                • 5. Re: Dynamically auto-center text fields?
                  George Johnson CommunityMVP

                  The main problem with your script is where you placed it. A field's calculation script is triggered whenever any field value changes. It worked initially when you were adding it because it is also triggered each time it is edited in Acrobat.

                  • 6. Re: Dynamically auto-center text fields?
                    shawninvancouver Community Member

                    George Johnson wrote:

                     

                    How about using a single test field that's centered and prompting the user (app.response or custom dialog) for the values that would normally go in the Name and Title field, and include the pipe character in the text field between the two values? You'd have to use a field formatted for rich text if you want to use different font styles and colors for the two values and set the field value using two spans. All of this would involve JavaScript.

                     

                    Rereading your original suggestion. If the user is prompted (i.e. the user doesn't directly interact with that single field), this would be an acceptable solution. Can you link me to any examples of this. I looked and was unsuccessful finding any suitable solutions that I could adapt to my project.

                     

                    Thank you.

                    • 7. Re: Dynamically auto-center text fields?
                      George Johnson CommunityMVP

                      I can post a sample later today. If anyone else wants to, please do.

                      • 8. Re: Dynamically auto-center text fields?
                        shawninvancouver Community Member

                        Hello George,

                         

                        I will really appreciate any assistance you can offer.

                         

                        In the meantime, and a little bit for proof of concept... I attempted a low-tech/no-code approach... but I think I discovered a bug in Adobe Acrobat's handling of OTF postscript fonts! (grrr... always something to foil my attempts). Adobe Acrobat is not correctly handling the font used in the rich text enabled form field. For instance, it seems impossible to get a normal non-bold, non-italic font.

                         

                        I posted another message about this problem, here:

                        Rich text field will not show proper font attributes! (Bug? - RTF OTF font handling)

                         

                        BTW, when I was playing with javascripts, this problem didn't seem to manifest itself. So it appears to only be a problem with direct inserting of rich text in a form field.

                         

                        Thanks again for your valued assistance.