Question
Search for Text in document and export
I get ewrror on the findtext, not sure how to fix
// Define the file path where you want to save the exported text
var exportFilePath = "C:\Users\270007378.RXLUSA\Documents\ExportedText.txt";
// Get the active document
var doc = app.activeDocument;
// Get the character style
var characterStyle = doc.characterStyles.itemByName(characterStyleName);
// Check if the character style exists
if (!characterStyle.isValid) {
alert("Character style not found: " + characterStyleName);
exit();
}
// Find all text with the specified character style
var foundTexts = doc.findText({
appliedCharacterStyle: characterStyle
}, false);
// Collect the text content
var collectedText = "";
for (var i = 0; i < foundTexts.length; i++) {
collectedText += foundTexts[i].contents + "\n";
}
// Write the collected text to a file
var file = new File(exportFilePath);
file.encoding = "UTF-8";
file.open("w");
file.write(collectedText);
file.close();
alert("Text exported to: " + exportFilePath);
