Convert Outlines back into Live text
Hi everyone,
About a month ago, I came up with the idea of creating a script to covert outlines back into live text and I'm happy to announce that we made it! I would like to thank @Mike Bro, @Laubender, @pixxxelschubser,
@m1b and @Manan Joshi for all the support and apologize if some of the questions raised were not clear in my previous posts.
So basicaly, the script makes a copy of the live text before going through the process of creating outlines, just make sure to create a new Character Style "Outlines" (without any formatting attibutes) and apply to the text you want to outline before running it.
var doc = app.activeDocument;
var myDoc = app.activeDocument;
if(doc.characterStyles.item("Outlines") == null) {
alert('Error!\nThe Character Style "Outlines" doesn'+"'"+'t exist. Create and apply the Character Style "Outlines" and try again.');
exit();
}
app.findTextPreferences = null;
app.findTextPreferences.appliedCharacterStyle = "Outlines";
var found = doc.findText();
for(var i =0;i<found.length;i++) {
var trans = found[i];
found[i].duplicate(LocationOptions.AT_BEGINNING , found[i]);
}
// create character style and condition
var new_Style = app.documents[0].characterStyles.add()
new_Style.name = "Original"
try{
myDoc.conditions.add({name:"Original", indicatorMethod:ConditionIndicatorMethod.USE_HIGHLIGHT, visible:false})
}catch(e){}
// apply style and condition to all duplications
app.findGrepPreferences=app.changeGrepPreferences=null;
app.findGrepPreferences.findWhat = "([\\S\\s]+)\\K\\1";
app.findGrepPreferences.appliedCharacterStyle = "Outlines";
app.changeGrepPreferences.changeTo = "";
app.changeGrepPreferences.appliedCharacterStyle = "Original";
app.changeGrepPreferences.appliedConditions = ["Original"];
doc.changeGrep();
// turn on auto-size
function main() {
var doc = app.activeDocument;
// reset grep prefs
app.findGrepPreferences = NothingEnum.NOTHING;
app.changeGrepPreferences = NothingEnum.NOTHING;
// find criteria
app.findGrepPreferences.appliedCharacterStyle = 'Outlines';
var found = doc.findGrep();
for (var i = 0; i < found.length; i++)
for (var j = 0; j < found[i].parentTextFrames.length; j++) {
var frame = found[i].parentTextFrames[j];
if (frame.isValid) {
frame.textFramePreferences.autoSizingReferencePoint = AutoSizingReferenceEnum.TOP_CENTER_POINT;
frame.textFramePreferences.autoSizingType = AutoSizingTypeEnum.HEIGHT_ONLY;
}
}
};
// end main
app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, 'Set Autosizing');
// create outlines
app.findTextPreferences = null;
app.findTextPreferences.appliedCharacterStyle = "Outlines";
var found = doc.findText();
for(var i =0;i<found.length;i++)
{
try{
found[i].createOutlines();
}catch(e){}
}
app.findTextPreferences = null;
// hide original
app.activeDocument.conditions.item("Original").visible = true;
app.activeDocument.conditions.item("Original").visible = false;
Then, you can use the code below to remove the outlines and make the live text visible. Please note that it only works if you use the script above for outlining in the first place.
var doc = app.activeDocument;
app.findTextPreferences = null;
app.findTextPreferences.appliedCharacterStyle = "Outlines";
var found = doc.findText();
for(var i =0;i<found.length;i++)
{
found[i].remove();
}
app.findTextPreferences = null;
// make original visible
myConditions = app.activeDocument.conditions;
app.activeDocument.conditions.itemByName("Original").remove();
// turn off auto-size
function main() {
var doc = app.activeDocument;
// reset grep prefs
app.findGrepPreferences = NothingEnum.NOTHING;
app.changeGrepPreferences = NothingEnum.NOTHING;
// find criteria
app.findGrepPreferences.appliedCharacterStyle = 'Original';
var found = doc.findGrep();
for (var i = 0; i < found.length; i++)
for (var j = 0; j < found[i].parentTextFrames.length; j++) {
var frame = found[i].parentTextFrames[j];
if (frame.isValid) {
frame.textFramePreferences.autoSizingType = AutoSizingTypeEnum.OFF;
}
}
};
// end main
app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, 'Set Autosizing');
// remove character styles
app.activeDocument.characterStyles.itemByName("Outlines").remove();
app.activeDocument.characterStyles.itemByName("Original").remove();
I hope you find it useful and any feedback would be greatly appreciated! 🙂
Regards,
Rogerio
