Adobe 0046100128056 Scripting Guide - Page 77
Exporting Text and Setting Text-Export Preferences
UPC - 718659087562
View all Adobe 0046100128056 manuals
Add to My Manuals
Save this manual to your list of manuals |
Page 77 highlights
CHAPTER 6: Text and Type Exporting Text and Setting Text-Export Preferences 77 Exporting Text and Setting Text-Export Preferences The following script shows how to export text from an InDesign document. Note that you must use text or story objects to export into text file formats; you cannot export all text in a document in one operation. (We omitted the myGetBounds function from this listing; you can find it in "Creating a text frame" on page 71," or see the ExportTextFile tutorial script.) var myDocument = app.documents.item(0); var myPage = myDocument.pages.item(0); var myTextFrame = myPage.textFrames.item(0); //Text exportFile method parameters: //Format as ExportFormat //To As File //[ShowingOptions As Boolean = False] //Format parameter can be: //ExportFormat.inCopy //ExportFormat.inCopyCS2Story //ExportFormat.rtf //ExportFormat.taggedText //ExportFormat.textType //Export the story as text. You'll have to fill in a valid file path on your system. myTextFrame.parentStory.exportFile(ExportFormat.textType, File("/c/test.txt")); The following example shows how to export a specific range of text. (We omitted the myGetBounds function from this listing; you can find it in "Creating a text frame" on page 71," or see the ExportTextRange tutorial script.) var myDocument = app.documents.item(0); var myStory = myDocument.stories.item(0); var myStart = myStory.characters.item(0); var myEnd = myStory.paragraphs.item(0).characters.item(-1); myText = myStory.texts.itemByRange(myStart, myEnd); //Text exportFile method parameters: //Format as ExportFormat //To As File //[ShowingOptions As Boolean = False] //Format parameter can be: //ExportFormat.inCopy //ExportFormat.inCopyCS2Story //ExportFormat.rtf //ExportFormat.taggedText //ExportFormat.textType //Export the text range. You'll have to fill in a valid file path on your system. myText.exportFile(ExportFormat.textType, File("/c/test.txt")); To specify the export options for the specific type of text file you're exporting, use the corresponding export preferences object. The following script sets text-export preferences (for the complete script, see TextExportPreferences): with(app.textExportPreferences){ //Options for characterSet: TextExportCharacterSet characterSet = TextExportCharacterSet.UTF8; //platform options: ImportPlatform platform = ImportPlatform.macintosh; } The following script sets tagged text export preferences (for the complete script, see TaggedTextExportPreferences):