Stefan Cameron on Forms
Building intelligent forms using Adobe LiveCycle Designer

Auto-splitting text between two text fields

The scenario

You have a compliant form that has sections for users to fill-in information. Because the form is compliant (i.e. its layout has received the “stamp of approval” and cannot change without another lengthy approval process), the sections cannot grow (they cannot expand-to-fit all of the text users may fill-in). To provide more space for users to add more text, you’ve provided an expandable “overflow” section at the end of form since expanding that section will not affect the portion of the form which has been approved.

The problem

You need to capture the text entered into the form using an interactive Form Guide which is not limited to the restrictions of the form’s approved layout. As such, the Form Guide will capture the text in a single field and you need that text to be entered into the PDF version of the form. If you put all the text into the appropriate section on the form, it won’t fit and the text will be cut-off (e.g. it will not print entirely and you will miss some of the important information).

You need some way to automatically split that text between the small section in the form and the overflow section at the end of the form. In other words, you need to ensure that only the text that can fit within the small form section is placed there and the rest is placed in the overflow section at the end.

In Designer 8.2, the content of fields can now be split between pages however in this case, you can’t use this feature because the small form section can’t be expanded (it’s fixed in size).

The solution

This is the problem Stephanie, Glenn and I were faced with on a recent customer visit. Stephanie took the time to put this into a sample form which provides the script we wrote to handle this task. It’s basically a mini text parser written in JavaScript that splits text between two fields with a fixed-width font (e.g. Courier New, Lucida Console, etc.).

Posted by Stefan Cameron on July 10th, 2008
Filed under Acrobat,Designer,Form Guides,Scripting,Tutorials
Both comments and pings are currently closed.

6 Responses to “Auto-splitting text between two text fields”

  1. Sergey on August 27th, 2008

    Is there some algorithm for variable font width to do the same split?

  2. Stefan Cameron on September 3rd, 2008


    Unfortunately not. There just isn’t enough font information available via APIs at your disposal in order to compute the correct character width on a per-character basis for a particular font, which is basically what the algorithm would need to do.

  3. neptas on October 23rd, 2008

    Hello Stefan,

    I was wondereing if you can help me on this (it´s about form guides, but not directly related with this scenario).
    Before using form guides, and because I knew that I could have a pdf inside it and formguide would make a mapping of value fileds into it, I thought I could use formguides to fill-in the form and execute any normal java script inside the form at the same time.

    However, it seems that the script will run inside the flash context. For instance, if I have a replace javascript function inside a change filed event, when I had a value to that field in a formguide, the change event will be fired. However, the replace function will throw an error. What functions can we use?
    Another example, if I have a floating field in a pdf, the form guide will do the mapping of the vlaue to the field, however, if I do a xfa.layout,.relayout, formguide will throw an error. BUT the floating field will actually work… Why I get such behavior? If this actually work in the PDF (making a preview from formguide) why we get this error?

    thank you

  4. Stefan Cameron on October 30th, 2008


    Form Guides are designed to execute your form in a Flash environment and mirror what is done in the PDF because you might decide to deploy a form as a Form Guide without the PDF behind it. The catch is that Form Guides (and HTML forms) operate on the XFA Subset which means that you don’t have access to all the APIs which you can access when your script executes in Acrobat/Reader.

    If you need to write scripts that use more than the subset in order to do special things only in the PDF, you need to “protect” that code with a check to ensure it executes only in the context of the PDF. You can do this by checking the value of the property. If it’s “Flash”, then your in the context of the Form Guide. Otherwise, you’re in the PDF:

    if ( != "Flash")
        // do the PDF-only/full-XFA stuff...
  5. perniciano on September 10th, 2009

    I need to massage the data from the field before I can assign it to the floating field, but the floating field either shows the original value or something else. Not the data I calculated.
    I’m passing a “date” as a string to a form variable and then getting it from there to the field.
    I had used the xfa.layout.relayout() with no change.

    any ideas?

  6. Stefan Cameron on September 17th, 2009


    Could you expand a little more on “getting it from there to the field”?