Skip to Content
Author's profile photo Prajesh Desai

Dynamic font setting for adobe forms

Changing font at runtime for all controls (fileds) in adobe form is quite painful, because till now there is no provision is given by adobe. I have done some RND on how to change fonts in our adobe forms dynamically. This will change font of whole pdf.

Requirement: Want to change font of whole pdf (all pages, master pages).

Solution:

First go through Loop through all controls (fields) in adobe forms blog for more information.

Below all listed controls (fileds) are effected,

  • Button, Check Box, Date/Time Field, Drop-down List, Signature Field, Image Field, List Box, Numeric Field, Password Field, Radio Button, and Text Field.
  • Circle, Line, Rectangle, Static Image, and Static Text.

 

Use below script on data node.

data::ready:layout - (JavaScript, client)
var totalPages = xfa.layout.pageCount();
var i = 0;

for (i = 0; i < totalPages; i++) {
  setFont("field", 0);
  setFont("draw", 0);
  setFont("field", 1);
  setFont("draw", 1);
}


function setFont(type, page) {
  var oField = xfa.layout.pageContent(i, type, page);
  var n = oField.length;
  var j = 0;

  for (j = 0; j < n; j++) {
    oField.item(j).font.typeface = "Courier"; //any valid font name
  }
}

Hope this helps.

Assigned Tags

      5 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Former Member
      Former Member

      Hi Prajesh,

      I am not able to change the font for the text getting added dynamically. Please help.

       

      Thanks.

      Author's profile photo Prajesh Desai
      Prajesh Desai
      Blog Post Author

      Same is going to work for dynamic text is well. please explain your issue in detail, if possible ask same with example in Q&A section.

      Hope this helps. 

      Author's profile photo saritha N
      saritha N

      Hi Prajesh,

      I have a requirement , i should reduce the font size of the label for particular company code in order fit the text in the label window. As i am new to this adobe especially the Java scripting.Please guide me, how to achieve this.

       

      Regards,

      Saritha

      Author's profile photo saritha N
      saritha N

      Kindly answer to the below question created :

      https://answers.sap.com/questions/349467/reduce-font-size-of-a-label-adobe-forms.html

       

      Author's profile photo Bamakam dubbu
      Bamakam dubbu

      How to replace text style for single word in internal table data using Java script in adobe forms

      Hello Team,

      In my adobe form internal table it_lines have text field which contains material description which gets displayed in adobe form as item table. .

      My requirement is to change one word style as ITALIC using Java scripts for example in below text "SAP" should be in ITALIC.

      Example: sample text "SAP" .

      I need to set loop for it_lines and replace "SAP" style as ITALIC using java scrip in adobe form

      Please someone help me with sample code.

      This question is related to Javascript which we use in adobe forms.

      I am using below code which is not working to change Status field style to "Italic"

      data.#subform[0].#subform[7].Table2.Row1.STATUS::ready:form - (JavaScript, client)

      var IMTEST = xfa.resolveNodes("$record.Table2.DATA[*]");

      var LV_DATA;

      for (var i = 0; i < IMTEST.length; i++) {

      LV_DATA = xfa.resolveNode("$record.Table2.DATA[" + i + "].STATUS").value;

      {

      this.STATUS.font.posture = "italic";

      }

      }

      Can someone please help me to correct the codeimage.png