ExtendScript - Set Text Stroke
Greetings!
I am trying to add a simple stroke to a text object in Illustrator using ExtendScript Toolkit. I have been following some documentation for interacting with the DOM, but I am having a hard time figuring out why this isn't working (no errors are thrown). I have tried printing the strokewidth and stroked boolean values after they are applied to the text, and they show stroked = true and the correct strokeWidth value. However, when I navigate to the directory where I export the file as png (also using the script), the image has no stroke on the text element I was trying to modify.
There must be something wrong with my code. Any help is much appreciated!
// select layer
doc.selection[0];
text = doc.activeLayer.pageItems.getByName("textLine1");
// define the color white
var newColor = new CMYKColor();
newColor.cyan = 0;
newColor.magenta = 0;
newColor.yellow = 0;
newColor.black = 0;
// add stroke to text
text.stroked = true;
text.strokeWidth = 9.2;
text.strokeColor = newColor;
// get Y position of text
yPos = text.position[1];
// if too big, reduce the size of the text
if (text.width >= 1620) {
targetWidth = 1620;
ratio = targetWidth/text.width;
text.width = targetWidth;
text.height = text.height * ratio;
}
// center of artboard and center of text element
docCenterX = doc.width/2;
textXRadius = text.width/2;
// assign new position for resized text
text.position = [docCenterX - textXRadius, yPos];
