• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Javascript font formatting for business card form spans.push

Explorer ,
Jun 10, 2022 Jun 10, 2022

Copy link to clipboard

Copied

I'm so stuck I need help. No matter what I've tried I can't get a font to change within my fields.

 

I'm building a business card template. My company has a software can than read the pdf form. There are visible fields that the user enters in and read only fields that populate all information into the proper placement and formating. There are also many variables based on what the user enters.

 

It's so close!! but I'm stuck on getting the Museo Sans font to display with both 300 and 900 on the same line. I'll attach both a form example and a pdf example of what it should look like. I need the form to apply Museo Sans 900 when the following letters populate within the emailfill field and the numbers fill field: "t:", "c:", "f:", "e:", "w:" I've exhausted every option trying to find a way to get it to change but not a single attempt has proven even remotely successful.

 

I also need the numbers to format in 000.000.0000, but I figured I'll deal with that after I figure out this other formating issue.

TOPICS
JavaScript , PDF forms

Views

565

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jun 11, 2022 Jun 11, 2022

Just like with the Name field, you have to use Rich Text Formatting if you want to have multiple fonts in a single text string. To specify a font, though, you have to know the internal font name. The easiest way to do that is to manually apply it to a text field (say "Text1") and then print out the textFont property to the console, like this:

 

console.println(this.getField("Text1").textFont);

 

Now take that value and use it in your Span object, as the first item in an array of strings under fo

...

Votes

Translate

Translate
Community Expert ,
Jun 11, 2022 Jun 11, 2022

Copy link to clipboard

Copied

Just like with the Name field, you have to use Rich Text Formatting if you want to have multiple fonts in a single text string. To specify a font, though, you have to know the internal font name. The easiest way to do that is to manually apply it to a text field (say "Text1") and then print out the textFont property to the console, like this:

 

console.println(this.getField("Text1").textFont);

 

Now take that value and use it in your Span object, as the first item in an array of strings under fontFamily, like this (here I'm using Times Roman, for example):

 

	spans.push({
		text: s1,
		textSize: 8,
		fontFamily: ["Times"],
		textColor: color.red
	});

 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 11, 2022 Jun 11, 2022

Copy link to clipboard

Copied

This works really well!! Thank you! I discovered I was really close with some of my attempts I was just missing the [] around the fontFamily name.

 

Regarding formating, how do I get any phone number to be formated to 000.000.0000 but also keep the custom calculation script. Just to see if it works, I applied: if(!event.value||event.value == " ") {
event.value = "";
}
else {
event.value = util.printx("999.999.9999", event.value);
}

 

to the Custom Format Script field of the "NumbersFill" field and it does take any number populated in this field and convert it, however it only chooses the first number in the sequence and drops the text written in the Custom Calculation Script.

 

Can I incorporate the Custom Format Script into the Custom Calcuation Script or do I need to have something in each?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 11, 2022 Jun 11, 2022

Copy link to clipboard

Copied

LATEST

You have to incorporate it into the calculation script, yes, but then it's not just a Format, it's changing the actual value. I don't think that matters in your case, though.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines