Skip to content

Instantly share code, notes, and snippets.

@hjhilden
Created April 23, 2026 07:40
Show Gist options
  • Select an option

  • Save hjhilden/d856baf5be28598aaac2423112837a88 to your computer and use it in GitHub Desktop.

Select an option

Save hjhilden/d856baf5be28598aaac2423112837a88 to your computer and use it in GitHub Desktop.
Adobe Illustrator: split text on line breaks
// Split Text on Line Breaks in Adobe Illustrator.
// Splits selected text object(s) into separate text paths for each line
// Retains font face, size and leading but not other character stylings, the placement is also a bit off
// Tested on Illustrator 30.2.1 (2026)
if (app.documents.length === 0) {
alert("Please open a document first.");
} else {
var doc = app.activeDocument;
var selection = doc.selection;
if (selection.length === 0) {
alert("Please select a text object.");
} else {
// Store selected items in a separate array
var textFrames = [];
for (var i = 0; i < selection.length; i++) {
if (selection[i].typename === "TextFrame") {
textFrames.push(selection[i]);
}
}
// Process each text item
for (var i = 0; i < textFrames.length; i++) {
splitTextFrame(textFrames[i]);
}
}
}
function splitTextFrame(textFrame) {
var content = textFrame.contents;
var lines = content.split(/\r\n|\r|\n/);
if (lines.length <= 1) {
return;
}
var x = textFrame.position[0];
var y = textFrame.position[1];
var layer = textFrame.layer;
var fontSize = textFrame.textRange.size;
var typeFace = textFrame.textRange.characterAttributes.textFont;
var lineSpacing = undefined
var lineSpacing = textFrame.textRange.characterAttributes.leading;
if (lineSpacing === undefined || lineSpacing === 0) {
lineSpacing = fontSize * 1.2;
}
var currentY = y;
for (var i = 0; i < lines.length; i++) {
if (lines[i].length > 0) {
var newText = layer.textFrames.add();
newText.contents = lines[i];
newText.position = [x, currentY];
newText.textRange.size = fontSize;
newText.textRange.characterAttributes.textFont = typeFace;
}
currentY -= lineSpacing;
}
textFrame.remove();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment