Skip to main content
4everJang
Legend
April 6, 2023
Answered

How to add unicode characters from extendscript

  • April 6, 2023
  • 2 replies
  • 1292 views

One of my scripts requires entering a unicode character, but I have not yet found the method to do so. I need to use the oDoc.AddText method, which requests the second parameter to be a text string. I can enter a unicode character in the script, but it needs to be pulled from an attribute which carries the unicode number for the character. So how do I go from unicode number to an actual character to be pushed into my doc?

Maybe this is trivial, but I am not getting any results with my trials so far. I have tried using the String.fromCharCode(  ) but that results in a question mark (indicating an unknown character).

Any help is greatly appreciated.

This topic has been closed for replies.
Correct answer Klaus Göbel

Hi Jang,

 

try this:

var sAttrValue = "2018";
var sCharCode = String.fromCharCode("0x" + sAttrValue);

2 replies

4everJang
4everJangAuthor
Legend
April 7, 2023

Thanks everyone. Nice to get help on various deep-technical things. As you may know, I keep pushing the boundaries of what FrameMaker can do. I am still very much covered in work but I am planning to share some of my scripting tricks when I find the time. Not here, where they will quickly be lost in all the other posts but in a dedicated corner of my Smart Information Design website, so that they remain available as sources of inspiration and reference to taming Frame.

frameexpert
Community Expert
Community Expert
April 6, 2023

Hi Jang, Try this:

#target framemaker

var doc, pgf, textLoc;

doc = app.ActiveDoc;
pgf = doc.TextSelection.beg.obj;
textLoc = new TextLoc (pgf, 0);

doc.AddText (textLoc, "\u03C3"); // sigma
Bob_Niland
Community Expert
Community Expert
April 6, 2023

re: \u03C3

Note that this works for Unicode BMP characters only (U+0000 to U+FFFF), 4 hex digit \u markup.

FM does not yet properly support any Supplementary Plane characters (U+10000 & up, no known markup notation).