Multi-line text in a button caption

Learn how to save space or provide more information to the user by placing multiple lines of text in a Button caption.

By July 7, 2006

 

Skill Level: Intermediate
Prerequisites: Familiarity with Form Fields and the JavaScript environment

It’s often useful, for saving space or providing more information to the user, to place multiple lines of text in a Button caption. This is something that cannot be done from the Acrobat user interface. However, it is easily accomplished with Acrobat JavaScript. All you need to know is the name of the Button Field.

First, let’s create a test document. Display the Acrobat JavaScript Window (Use Ctrl+J for Windows or Command+J for the Mac, or from the Advanced menu). Enter and run the following code to create a new PDF.

app.newDoc();

Now select the Button tool from the Advanced Editing toolbar. Create a Button Field and name it “MyButton”.

Display the Acrobat JavaScript Console again. Enter and run the following code to put two lines into the caption of the Button.

this.getField("MyButton").buttonSetCaption("Hello\nWorld");

The words “Hello” and “World” each appear on different lines because they are separated with “\n”. The forward slash (“\”) is the escape character. It gives the next character in the sequence a special meaning. In this case, “\n” inserts a new line into the string. You can insert this character sequence as many times and anywhere you want in a string to add new lines in the text.


Figure 1: PDF Button Field
with multi-line caption


Did you know?

  • You can ask a question and get an answer from one of our experts.
  • You can search our database of over 800 tutorials by product and/or topic.
  • You can leave a comment below for the author of this tutorial.

Related topics:

PDF Forms, JavaScript

Top Searches:

Convert existing forms to fillable PDFs, fill and sign any form, Edit PDF, create PDF, Action Wizard

0 comments

Comments for this tutorial are now closed.

Comments for this tutorial are now closed.