Skip to main content
Known Participant
July 13, 2023
Answered

change font in text field exceeded num characters, retroactive. adobe acrobat

  • July 13, 2023
  • 8 replies
  • 11120 views

Ciao, dal momento che ho campi di testo che non posso aumentare la loro dimensione, vorrei essere in grado di cambiare il carattere per poter inserire più caratteri. Poiché devo mantenere il carattere originale il più possibile per la maggior parte dei campi di testo, vorrei creare un'eccezione, solo quando una parola inserita in uno di questi campi di testo ha più caratteri di quelli che può adattare. Tuttavia, tutto deve essere retroattivo. Qualcuno può aiutarmi, grazie

This topic has been closed for replies.
Correct answer try67

That's not possible, either. You can change those values, sure, but it would only take affect once the user exits the field. The text font and/or size won't be updated while they are entering text into it.


Attached is a file that shows that font.TimesB works just fine (I used Arial for the long text).

Long text:

 

Short text:

 

Code:

 

if (event.value.length > 10) {
	event.target.textFont = "Arial"; // Replace with the desired font name
	event.target.textSize = 9; // Replace with desired font size
} else {
	event.target.textFont = font.TimesB; // Replace with the original font name
	event.target.textSize = 7; // Replace with original font size
}

8 replies

JR Boulay
Community Expert
Community Expert
August 21, 2023

Désolé j'étais en vacances.

Il y a peut être une erreur dans la documentation.

Acrobate du PDF, InDesigner et Photoshopographe
Known Participant
August 21, 2023

Grazie mille JR Boulay. Il vostro aiuto e la vostra pazienza sono stati inestimabili. Grazie a voi e alla community sono riuscito a raggiungere l'obiettivo. Un grande forum!

Known Participant
August 9, 2023

I need to fix this. Convert font exceeded x num characters in text field, with retroactive function. I attach PDF files. Thanks everyone for the help.

Known Participant
August 14, 2023

The javascript that JR Boulay recommended to me is in the text box: Name. Unfortunately I couldn't get it to work. Please help me

Bernd Alheit
Community Expert
Community Expert
August 15, 2023

Any error in the Javascript console?

JR Boulay
Community Expert
Community Expert
July 29, 2023

Il est très difficile d'aider quelqu'un qui ne suit pas ce qu'on lui dit et qui répond toujours à côté de la question.

Acrobate du PDF, InDesigner et Photoshopographe
Known Participant
August 6, 2023

Ho allegato il file PDF come richiesto. Mi scuso per la mia inesperienza in questo ambiente. Se sto facendo qualcos'altro mi piacerebbe saperlo per non creare altri inconvenienti. Grazie

JR Boulay
Community Expert
Community Expert
July 23, 2023

Can you share (part of) this form?

Acrobate du PDF, InDesigner et Photoshopographe
Known Participant
July 28, 2023

Ho creato un nuovo file pdf vuoto, inserito un campo di testo e seguito le tue istruzioni. Purtroppo il risultato è quello che vedete nella foto.

Bernd Alheit
Community Expert
Community Expert
July 29, 2023

Share the pdf file.

JR Boulay
Community Expert
Community Expert
July 22, 2023

If you don't know how to use a function it will be easier to use this simplified script as a Validation script in the field "Nome" (or in any other text field):

 

 

if (event.value.length > 10) {
event.target.textFont = font.TwCenMTCondensed; // Sostituisci con il nome del font desiderato
event.target.textSize = 9; // Sostituisci con la dimensione del font desiderata
}
else {
event.target.textFont = font.TimesB; // Sostituisci con il nome del font originale
event.target.textSize = 7; // Sostituisci con la dimensione del font originale
}

 

 

Acrobate du PDF, InDesigner et Photoshopographe
Known Participant
July 22, 2023

I followed your instructions, I copied and pasted your javascript.

The debugger responds like this:

InvalidSetError: Impossible, invalid or unknown setting.

Field.textFont:2:Field Name:Validate

But all this after pressing the mouse button outside the text field. My goal is to have the font change in real time while writing in the text field exceed a certain number of characters. And equally important is to return to the original font if you return to the set number of characters. Thanks for your help and patience.

JR Boulay
Community Expert
Community Expert
July 21, 2023

There are font name issues:

 

function updateFont() {
var textField = this.getField("Nome");
var textValue = textField.valueAsString;
var characterLimit = 10; // Sostituisci con il limite di caratteri desiderato

if (textValue.length > characterLimit) {
textField.textFont = font.Tw Cen MT Condensed; // Sostituisci con il nome del font desiderato
textField.textSize = 7; // Sostituisci con la dimensione del font desiderata
} else {
textField.textFont = font.TimesB; // Sostituisci con il nome del font originale
textField.textSize = 7; // Sostituisci con la dimensione del font originale
}
}

 

Times Bold JavaScript keyword is easy to find because it's a standard font, but for the other one you'll need to use a script to get its keyword name in JavaScript (there can be no spaces in the JavaScript keyword of a font).

 

Search for "font Object" on this page: https://opensource.adobe.com/dc-acrobat-sdk-docs/library/jsapiref/JS_API_AcroJS.html#field-properties

 

You will find this:

Use of arbitrary fonts

Beginning with Acrobat 5.0, an arbitrary font can be used when laying out a text field, combo box, list box or button by setting the value of textFont to the PDSysFont font name, as returned by PDSysFontGetName.

 

To find the PDSysFont font name of a font:

- Create a text field in a PDF document. Using the UI, set the text font for this field to the desired font.

- Open the JavaScript Debugger Console and execute the script:

 

 

this.getField("Text1").textFont

 

 

(The above code assumes the name of the field is Text1.)

- The string returned to the console is the font name needed to programmatically set the text font.

Acrobate du PDF, InDesigner et Photoshopographe
Known Participant
July 21, 2023

var textField = this.getField("Nome");
textField.setAction("Keystroke", "updateFont();");

function updateFont() {
var textField = this.getField("Nome");
var textValue = textField.valueAsString;
var characterLimit = 10; // Sostituisci con il limite di caratteri desiderato

if (textValue.length > characterLimit) {
textField.textFont = font.TwCenMTCondensed; // Sostituisci con il nome del font desiderato
textField.textSize = 7; // Sostituisci con la dimensione del font desiderata
} else {
textField.textFont = font.TimesB; // Sostituisci con il nome del font originale
textField.textSize = 7; // Sostituisci con la dimensione del font originale

}
}

 

InvalidSetError: Impossible, invalid or unknown setting. Field.textFont:10:Field Name:Keystroke

 

thanks for the previous reply. Can you help me understand where I'm going wrong now? I inserted this javascript in the action of the text field "MOUSE DOWN"

Bernd Alheit
Community Expert
Community Expert
July 22, 2023

Why does you use setAction?

JR Boulay
Community Expert
Community Expert
July 17, 2023

Je ne comprend pas votre réponse.

Est-ce que ça fonctionne oui ou non ?

 

Si non merci de poster le script, pas une image.

Acrobate du PDF, InDesigner et Photoshopographe
Known Participant
July 20, 2023

function updateFont() {
var textField = this.getField("Nome");
var textValue = textField.valueAsString;
var characterLimit = 10; // Sostituisci con il limite di caratteri desiderato

if (textValue.length > characterLimit) {
textField.textFont = font.Tw Cen MT Condensed; // Sostituisci con il nome del font desiderato
textField.textSize = 7; // Sostituisci con la dimensione del font desiderata
} else {
textField.textFont = font.Times Bold; // Sostituisci con il nome del font originale
textField.textSize = 7; // Sostituisci con la dimensione del font originale
    }
}

 

adobe acrobat gives me this error: InvalidSetError: Impossible, invalid or unknown setting. Field.textFont:9:Field Name:Keystroke

Bernd Alheit
Community Expert
Community Expert
July 21, 2023

This is a issue with the spaces in the font names.

Bernd Alheit
Community Expert
Community Expert
July 14, 2023

You can set the font size to Auto.

Known Participant
July 14, 2023

Grazie per la risposta, ma la mia domanda è di cambiare il carattere, non la dimensione, in un certo numero di caratteri inseriti e retroattivi.

Known Participant
July 14, 2023