SAP Knowledge Base Article - Public

1218239 - How to format a single string with multiple fonts in Crystal Reports?

Symptom

  • How to use multiple fonts in one string?
  • How to display multiple font types within a single string in Crystal Reports?
  • For example: When formatting an address to be consistent with a company standard, numbers must display in Arial while all other characters must display in Times New Roman. How can you display multiple fonts in a string in Crystal Reports?

Environment

  • SAP Crystal Reports 2016
  • SAP Crystal Reports 2020
  • SAP Crystal Reports 2025     

Resolution

  • Formatting a string with multiple fonts, can be achieve using the following Text Interpretation feature in Crystal Reports:
    • HTML Text Interpretation
    • RTF Text Interpretation.
         
  • To format the text, create a formula using the field you intend to display multiple font types, and loop through the string and add RTF or HTML text interpretation syntax where required to add multiple fonts.
      
           
  • Using HTML text interpretation to format a string with multiple fonts
        
    1. In Crystal Reports, create a formula that will add html tags to change the fonts within the string.  The formula will look like:

      // This sets the evaluation time of the formula.
      WhilePrintingRecords;

      // These three variables are used to loop through the existing string and create
      // the required HTML text interpretation syntax.
      NumberVar i := 0;
      StringVar Starter := "";
      StringVar CharString := "";
          
      //This begins the HTML block.
      Starter := "<html><body>";
        
      //This forces the formula to loop through each character in the string individually.
      For i := 1 to length({Employee Addresses.Address1}) do

      //This checks to see whether or not the current character can be converted to a number. If yes, that character is
      //added to the CharString variable with a font specification of Arial. If the character cannot be converted to a number,
      //it is added to the CharString variable with a font specification of Times New Roman.
      (
         if isnumeric({Employee Addresses.Address1}[i]) then 
              CharString := CharString + "<font face='Arial'>" + {Employee Addresses.Address1}[i] + "</font>"
         else 
              CharString := CharString + "<font face='Times New Roman'>" + {Employee Addresses.Address1}[i] + "</font>"
      );

      //This concatenates the entire formula output, including required HTML text interpretation information.
      Starter + CharString + "</body></html>";
        
    2. Insert the formula on the report where you want to display the text.
    3. Right click on the formula inserted on the report, and select "Format Field"
    4. In the "Format Editor", under the tab "Paragraph", set the option: "Text Interpretation" to: "HTML Text"
    5. Click "OK"

 

  •  Using RTF text interpretation to format a string with multiple fonts

 

    1. n Crystal Reports, create a formula that will add html tags to change the fonts within the string.  The formula will look like:

      //This sets the evaluation time of the formula.
      WhilePrintingRecords;

      //These three variables are used to loop through the
      //existing string and create the required RTF text
      //interpretation syntax.
      NumberVar i := 0;
      StringVar Starter := "";
      StringVar CharString := "";

      //This sets the default language and starts the font
      //table block.

      Starter := '{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl';

      //This adds the Times New Roman font to the table as f0.
      Starter := Starter + '{\f0\froman\fcharset0\fprq2 Times New Roman;}';

      //This adds the Arial font to the table as f42.
      Starter := Starter + '{\f42\fswiss\fcharset0\fprq2 Arial;};}';

      //This forces the formula to loop through each character
      //in the string individually.
      for i := 1 to length({Employee_Addresses.Address1}) do

      //This checks to see whether or not the current character
      //can be converted to a number. If yes, that character is
      //added to the CharString variable with a font specification
      //of Arial. If the character cannot be converted to a number,
      //it is added to the CharString variable with a font specification
      //of Times New Roman.
      (
         if isnumeric({Employee_Addresses.Address1}[i])
         then CharString := CharString + '\cf' + totext(i,0,'') + '\f42 ' + {Employee_Addresses.Address1}[i]
         else CharString := CharString + '\cf' + totext(i,0,'') + '\f0 ' + {Employee_Addresses.Address1}[i]
      );

      //This concatenates the entire formula output, including
      //required RTF text interpretation information.
      Starter + CharString + '\cf0\par}';

        
    2. Insert the formula on the report where you want to display the text.
    3. Right click on the formula inserted on the report, and select "Format Field"
    4. In the "Format Editor", under the tab "Paragraph", set the option: "Text Interpretation" to: "RTF Text"
    5. Click "OK"

 

  • Important Note:
    After you have applied the RTF or HTML text interpretation, modifying the format options in the Format Editor will not affect the look of the field. Therefore, other formatting aspects, such as font size, must be manipulated within this formula as well.

Keywords

CR, HTML, RTF , KBA , BI-RA-CR , Crystal Reports designer or Business View Manager , How To

Product

SAP Crystal Reports 2016 ; SAP Crystal Reports 2025