Skip to main content
artsoftorri
New Participant
February 9, 2023
Question

How to create an expandable interactive text box for PDF

  • February 9, 2023
  • 6 replies
  • 76675 views

I just finished creating an interactive pdf but the text boxes I created wont expand when the text box is full, it keeps going but wont to the next line (I dont know how to explain it). Is there a way to have an expandable interactive text box or would I need to use another app?

6 replies

New Participant
April 24, 2024

What I find sad is that LiveCycle (XFA) does this VERY WELL! However, Adobe (and Mac) have decided for some reason not to incorporate WONDERFUL product into something REALLY useful.

 

Browser based readers can't work with XFA.
Windows users can flatten XFA forms by printing to PDF, but MAC has removed the ability to do that.

 

It is really a shame. I did some pretty amazing things with expanding fields/documents, multiple pages, and (with some help from iText) form reading/manipulation. This unwillingness to allow others to access XFA forms really is unfortunate. They have unnecessarily limited their product.

New Participant
December 19, 2023

This was easy to do in Adobe Livecycle. However, that product was decommissioned to make way for AEM which is not really affordable for most. 

 

TᴀW
Brainiac
February 10, 2023

Here's a proof-of-concept. It's quite cool in a geeky way 8-)

The attached PDF has 2 text fields that expand as needed to accommodate the text. As the top field expands, it pushes the rest of the form down.

To see how this is done, take a look at the custom keystroke script attached to the text fields (copied below).

This has been tested and works in Acrobat. It requires a PDF reader with full Javascript support (like the free Adobe Reader on desktop).

 

if ( event.fieldFull )
{
	theFields = ["Text Field 2", "Text Field 3"];
	// Move other fields down
	for (i = 0; i < theFields.length; i++){
		f = this.getField(theFields[i]);
		b = f.rect;
		b[1] -= 20;
		b[3] -= 20;
		f.rect = b;
	}
	// Enlarge active field
	f = event.target;
	b = f.rect;
	b[3] -= 20;
	f.display = display.hidden;
	f.rect = b;
	event.change = event.changeEx;
	f.display = display.visible;
	f.setFocus();
}

 

New Participant
November 2, 2023

Can I ask where this code goes when creating the expandable PDF? I'm not a "coder". I have a PDF that I 'm testing and I can't seem to figure out where exactly to put the script. Thank you. 

New Participant
November 2, 2023

I found where you put it but mine doesn't seem to do anything.  Any help is appreciated. 

TᴀW
Brainiac
February 10, 2023

It is possible by attaching some Javascript to the format event of the text field.

As the user types, you would keeping checking whether the field overflows, and if it does, expand it (modify its coordinates).

It's a little trickier to shrink the field as needed (because then there is no overflow, so how to know it's not filled?)

I don't have the Javascript to hand, and will try to post it later. I have played around with it in the past, and it is a little messy -- I think there was a problem of the input cursor jumping to the beginning of the field when the field was expanded.

Also, unless this is the last field in the form, what will you do if fields start overlapping. And what will you do if you reach the bottom of the page? (Again, these issues could be solved by reprogramming the coordinates of all the other fields, I guess).

I'll try to post something later, but it's a bit of a messy solution, I think...

BobLevine
Community Expert
February 10, 2023

Messy is probably an understatement. I intentionally didn't mention trying that because another scenario is having multiple fields doing this. It's one of those things that I would file under "just because you can, doesn't mean you should."

This type of thing is best reserved for responsive forms on websites.

New Participant
April 24, 2024

What I find sad is that LiveCycle (XFA) does this VERY WELL!  However, Adobe (and Mac) have decided for some reason not to incorporate WONDERFUL product into something REALLY useful. 

Browser based readers can't work with XFA.
Windows users can flatten XFA forms by printing to PDF, but MAC has removed the ability to do that.

It is really a shame.  I did some pretty amazing things with expanding fields/documents, multiple pages, and (with some help from iText) form reading/manipulation.  This unwillingness to allow others to access XFA forms really is unfortunate.  They have unnecessarily limited their product. 

BobLevine
Community Expert
February 9, 2023

Set your text field up to be multiline and scrollable. There is no way to make the text field expand.

 

New Participant
May 28, 2024

Bob, it's so helpful when one needs an answer to a problem, and someone posts a simpledescription with a screenshot. Thanks, Amigo! My text fields are now multiline!

 

Derek Cross
Community Expert
February 9, 2023

You create your form in InDesign and fine tune it in Acrobat Pro.
You can't expand the size of the Text field once it's created but you can change the properties to multi-line and scroll long text so you can get more text in the field (you can limit the number of characters in the field too) . Do this under the Options tab in Text Field Properties in Acrobat Pro.