Skip to main content
Inspiring
March 11, 2022
Answered

textFont : Set not possible, invalid or unkown.

  • March 11, 2022
  • 2 replies
  • 1986 views

According to the docs I can use textFont to set a font for a field . when I try that I get an error:

 

InvalidSetError: Set not possible, invalid or unknown.
Field.textFont:11:Menu Set Fields:Exec

 

How can I successfully set a font for a field?

This topic has been closed for replies.
Correct answer try67

Display names, internal names? what do you mean?


Display names: The name of the fonts you see in the fonts selection list of a text field.

For example, "Myriad Pro Bold".

 

Internal names: The names used behind-the-scenes in a PDF file to represent a font. These values are the ones returned by the textFont property, and the only ones that will work when applied to it.

For example, "MyriadPro-Bold".

2 replies

try67
Community Expert
Community Expert
March 11, 2022

In order to find out the correct name for the font you want to use the best (and maybe only) way is to apply it to a field and then print out that field's textFont property to the JS Console. Then copy that text into your script.

Inspiring
March 11, 2022

@Bernd Alheit Thanks, I can try that.

 

@try67 : Font names do have space or am I wrong here?

Inspiring
March 11, 2022

I can confirm that this function to set all the fonts for text fields works:

function set_all_fields()
{
    console.show();

	for(var n=0; n<this.numFields; n++) {
		var fieldName = this.getNthFieldName(n);
		var field = this.getField(fieldName);
		console.println(fieldName);
		switch(field.type) {
			case 'text' :
				field.textFont = 'SourceSansPro';
				field.textSize = 9;
				break;
			case 'checkbox':
				field.style = style.ch;
				break;
			default: console.println(field.type);
				break;
		}
	}
}

 

and set the font family to "Source Sans Pro" (not "SourceSansPro")

Inspiring
March 11, 2022

This is the code: 

field.textFont = 'Source Sans Pro';
Bernd Alheit
Community Expert
Community Expert
March 11, 2022

Is the font name correct?

try67
Community Expert
Community Expert
March 11, 2022

It's not. It can't have spaces in it.