I have a script for photoshop which outputs the name of a text layer and layer content into Excel CSV file. It works fine if the text is english but if the text is Arabic/Thai it was displayed like this "??????". How can I display these texts properly?
My script gets the layername and layer content like this:
var iLayer = app.activeDocument.activeLayer.textItem;
var LayerContents = iLayer.contents;
Then output the names in the Excel file like this:
var Names =[ ];
Names.push([LayerName + "," + LayerContents]);
I tried changing the font style to Arial for Arabic and Tahoma for Thai, but it doesn't worked. I even tried converting LayerContents.toString();
You need to set your text to Unicode. In the example below I'll write the layer name to a text file. The principal is the same for CSV.
// refer to the source document
var srcDoc = app.activeDocument;
var myLayerName = srcDoc.activeLayer.name; // ملعقة
alert(myLayerName) // alerts fine;
write_text(myLayerName, "C:\\temp\\layer_name.txt");
function write_text(str, apath)
{
// create a reference to a file for output
var txtFile = new File(apath);
// open the file, write the data, then close the file
txtFile.encoding = "UTF8"; // make it unicode
txtFile.open("w", "TEXT", "????");
txtFile.writeln(str);
txtFile.close();
}
来源:https://stackoverflow.com/questions/39314554/output-arabic-thai-text-in-excel-file-using-photoshop-javascript