Acrobat Pro DC - Javascript Assistance

Hi Y’all

I’m working on making a PDF interactive for a client using Acrobat Pro DC and have a problem which I hope can be fixed with a bit of Javascript Assistance.

Initially, I had all the text boxes on the form set to a fixed 8pt size and allowed ‘multi line’ and ‘scroll long text’ options, which worked fine.

However, client then told me that they have a legal obligation to print all text that has been entered into the fields so I had to disactivate the scrolling option to ensure everything would remain in the boxes when printed.

Unfortunately, client is now not happy that they sometimes don’t have enough space available to enter all the copy required!

To overcome this, I then set the point size to Auto, allowed multi-line and removed scrolling so that the point size is reduced to ensure the text fits in the fields and is printed.

This works, but the customer is not happy that when they start to type into the fields the font looks so big.

Is there any way I can use javascript to set a ‘default’ point size of say 8 for my text fields, and then get the point size to reduce only in the instance there is too much copy entered for the field.

Many thanks in advance
Chris

I’ve experienced the same exact problem, and my searches (now and in the past) find several methods for solving it, but I can’t seem to make any of them work. I’ll let you know if I get anywhere with it.

Thanks for the feedback HB! I had a chat session with Adobe this morning and they said the only way I would be able to fix this would be to write a Javascript - although that didn’t really help me as I haven’t got a clue what Javascript is required or how to write it anyway!

No problem Chris. Essentially, we should be able to control the behavior, and create a field that applies a set font size, conditionally until the character count exceeds a threshold we set, then switches to “Auto” with Javascript that goes something like this:
var a = event.value.length;
if ((a < 10) || (a =="")){
getField(“Text1”).textSize = 12;
}
else getField(“Text1”).textSize = 0;

Theoretically, this would keep the font size in your field at 12 points as long as the character count is less than 10, otherwise it would be 0 (which is ‘Auto’). The problem is that this fails to override the font size that is set in the field’s normal Properties dialog. I’ve found posts by people who swear this works, and others who say it can’t. I’ve tried it quite a few different ways and have yet to succeed.

Thanks HB … I’ll give it a try.

I did find on the Adobe forums a similar script which had been marked as ‘correct answer’ which seems to be basically doing the same as yours…

var len = event.target.value.toString().length;
If (Len < 4) {
	event.target.textSize = 18;
}
else  {
	event.target.textSize = 0;
}	

So hopefully, one of these methods will give me a default point size until a certain character limit is reached and then it flicks across to zero size.

I’ll keep you posted!

Hi Folks

I thought I’d add an update into this ticket as I finally got this to work (sort of!).

We had to add two actions to all of the boxes that needed the text to be controlled.

The two actions were as follows…

On Focus -> Run Javascript

event.target.textSize = 0;

On Blur -> Run Javascript

var len = event.target.value.toString().length;

if (len < 44) {
event.target.textSize = 8;
}

else {
event.target.textSize = 0;
}

I hope this helps anybody else with the same problem!

Thanks

Chris

1 Like

©2019 Graphic Design Forum | Contact | Legal | Twitter | Facebook