Activity › Forums › Adobe InDesign › Best way to export text from InDesign?
-
Best way to export text from InDesign?
Posted by Jacki Schklar on May 1, 2007 at 12:54 pmI can export text story by story. Any way to export all the text from InDesign? And what’s this InCopy I’m reading about? This is something I may do regularly, so I might want a plug-in.
Taavi Tuisk replied 12 years, 9 months ago 12 Members · 25 Replies -
25 Replies
-
Jacki Schklar
May 1, 2007 at 6:39 pmI was given this on the Adobe forum, it has a text exporter for InDesign to .rtf or .txt.
Has anyone used these?
Also, more importantly, does InDesign CS3 have the capability to do this? I’ll wait if it does. We’ll get CS3 at some point.
-
Mike Gondek
May 2, 2007 at 2:44 pmUSing the text tool, to select a text box you can choose file >> export, and you will get the formats (.rtf, .txt).
I have not used the text exporter mentioned, so it may have more features such as exporting by pages rather than linked text.
I do often use somehting called puretext on the PC. It pastes the clipboard as unformatted text, so I can pick up the formatting from the target document in another application.
-
Jacki Schklar
May 2, 2007 at 11:23 pmYou can export story by story that way Mike, but I believe it does not export the whole document, which is what I want. You can export all the layout text from a pdf, but it is not formatting exactly how I need for some file comparisons. I did go ahead and download that tool and it’s AWESOME. I think. Only had time to try it once. But it worked and the text was formated really nicely.
I also got the trial of InCopy and it seems like too much trouble to deal with for this purpose.
-
Tim Cole
May 3, 2007 at 3:08 amThere are Mac and Win versions of an ID script that exports all stories in a document as separate files. What’s your platform?
– TC
-
Jacki Schklar
May 3, 2007 at 3:51 amMostly mac. We have production pc’s too though. I don’t want separate. I want together, but formatted better that you get from a pdf. I think the rorohiko plugin is going to do the trick. InCopy does the export by story thing for both platforms. Not relevant for what I’m doing.
-
Jacki Schklar
May 8, 2007 at 9:07 pmOK, this plugin is listing some of the text more than once, can’t have that. So I still have not solved the issue. How can I export text from InDesign to one Word doc, .rtf, or .txt? Anybody?…
-
Tim Cole
May 9, 2007 at 8:29 pmJacki,
This script exports ALL of the text in an ID dodument into one text file. It’s the CS3 version, but Ole Kvern, the author says it should run in CS2.
Copy and paste this into a text editor, save it as text only (i.e., not RTF) and name it EportAllText.jsx.
Toss it into your scripts folder and give it a try.
TC
//ExportAllText.jsx
//An InDesign CS3 JavaScript
//
//Exports all of the text in the active document as a single
//text file. To do this, the script will create a new document,
//combine the stories in the new document using export/import,
//and then export the text from the new document.
if(app.documents.length != 0){
if(app.documents.item(0).stories.length != 0){
myExportAllText(app.documents.item(0).name);
}
}
function myExportAllText(myDocumentName){
var myStory;
//File name for the exported text. Fill in a valid file path on your system.
var myFileName = “/c/test.txt”;
//If you want to add a separator line between stories, set myAddSeparator to true.
var myAddSeparator = true;
var myNewDocument = app.documents.add();
var myDocument = app.documents.item(myDocumentName);
var myTextFrame = myNewDocument.pages.item(0).textFrames.add({geometricBounds:myGetBounds(myNewDocument, myNewDocument.pages.item(0))});
var myNewStory = myTextFrame.parentStory;
for(myCounter = 0; myCounter < myDocument.stories.length; myCounter++){ myStory = myDocument.stories.item(myCounter); //Export the story as tagged text. myStory.exportFile(ExportFormat.taggedText, File(myFileName)); //Import (place) the file at the end of the temporary story. myNewStory.insertionPoints.item(-1).place(File(myFileName)); //If the imported text did not end with a return, enter a return //to keep the stories from running together. if(myCounter != myDocument.stories.length -1){ if(myNewStory.characters.item(-1).contents != "\r"){ myNewStory.insertionPoints.item(-1).contents = "\r"; } if(myAddSeparator == true){ myNewStory.insertionPoints.item(-1).contents = "----------------------------------------\r"; } } } myNewStory.exportFile(ExportFormat.taggedText, File("/c/test.txt")); myNewDocument.close(SaveOptions.no); } function myGetBounds(myDocument, myPage){ var myPageWidth = myDocument.documentPreferences.pageWidth; var myPageHeight = myDocument.documentPreferences.pageHeight if(myPage.side == PageSideOptions.leftHand){ var myX2 = myPage.marginPreferences.left; var myX1 = myPage.marginPreferences.right; } else{ var myX1 = myPage.marginPreferences.left; var myX2 = myPage.marginPreferences.right; } var myY1 = myPage.marginPreferences.top; var myX2 = myPageWidth - myX2; var myY2 = myPageHeight - myPage.marginPreferences.bottom; return [myY1, myX1, myY2, myX2]; } -
Tim Cole
May 9, 2007 at 8:37 pmJacki, note that this line of the script:
var myFileName = “/c/test.txt”;
requires you to enter a valid path for the file export…i.e., where you want the txt file to be saved.
Ole is going to add some UI to the script to eliminate that need asap. I’ll post it as soon as he sends it to me. In the meantime, this one should do what you need.
TC
-
Tim Cole
May 9, 2007 at 9:17 pmOK, here’s a version that throws up a dialog box asking you where you’d like to save your text file rather than forcing you to enter a path.
If you have any problems running this in CS2, let me know.
TC
//ExportAllText.jsx
//An InDesign CS3 JavaScript
//
//Exports all of the text in the active document as a single
//text file. To do this, the script will create a new document,
//combine the stories in the new document using export/import,
//and then export the text from the new document.
if(app.documents.length != 0){
if(app.documents.item(0).stories.length != 0){
myGetFileName(app.documents.item(0).name);
}
}
function myGetFileName(myDocumentName){
var myFilePath = File.saveDialog(“Save Exported File As:”);
if(myFilePath != null){
myDisplayDialog(myDocumentName, myFilePath);
}
}
function myDisplayDialog(myDocumentName, myFilePath){
//Need to get export format, story separator.
var myExportFormats = [“Text Only”, “Tagged Text”, “RTF”];
var myDialog = app.dialogs.add({name:”ExportAllStories”});
with(myDialog.dialogColumns.add()){
with(dialogRows.add()){
with(dialogColumns.add()){
var myExportFormatDropdown = dropdowns.add({stringList:myExportFormats, selectedIndex:0});
}
}
with(dialogRows.add()){
var myAddSeparatorCheckbox = checkboxControls.add({staticLabel:”Add separator line”, checkedState:true});
}
}
var myResult = myDialog.show();
if(myResult == true){
var myExportFormat = myExportFormats[myExportFormatDropdown.selectedIndex];
var myAddSeparator = myAddSeparatorCheckbox.checkedState;
myDialog.destroy();
myExportAllText(myDocumentName, myFilePath, myExportFormat, myAddSeparator);
}
else{
myDialog.destroy();
}
}
function myExportAllText(myDocumentName, myFilePath, myExportFormat, myAddSeparator){
var myStory;
var myTempFolder = Folder.temp;
var myTempFile = File(myTempFolder + “/tempTextFile.txt”);
var myNewDocument = app.documents.add();
var myDocument = app.documents.item(myDocumentName);
var myTextFrame = myNewDocument.pages.item(0).textFrames.add({geometricBounds:myGetBounds(myNewDocument, myNewDocument.pages.item(0))});
var myNewStory = myTextFrame.parentStory;
for(myCounter = 0; myCounter < myDocument.stories.length; myCounter++){ myStory = myDocument.stories.item(myCounter); //Export the story as tagged text. myStory.exportFile(ExportFormat.taggedText, myTempFile); //Import (place) the file at the end of the temporary story. myNewStory.insertionPoints.item(-1).place(myTempFile); //If the imported text did not end with a return, enter a return //to keep the stories from running together. if(myCounter != myDocument.stories.length -1){ if(myNewStory.characters.item(-1).contents != "\r"){ myNewStory.insertionPoints.item(-1).contents = "\r"; } if(myAddSeparator == true){ myNewStory.insertionPoints.item(-1).contents = "----------------------------------------\r"; } } } switch(myExportFormat){ case "Text Only": myFormat = ExportFormat.textType; myExtension = ".txt" break; case "RTF": myFormat = ExportFormat.RTF; myExtension = ".rtf" break; case "Tagged Text": myFormat = ExportFormat.taggedText; myExtension = ".txt" break; } myNewStory.exportFile(myFormat, File(myFilePath)); myNewDocument.close(SaveOptions.no); myTempFile.remove(); } function myGetBounds(myDocument, myPage){ var myPageWidth = myDocument.documentPreferences.pageWidth; var myPageHeight = myDocument.documentPreferences.pageHeight if(myPage.side == PageSideOptions.leftHand){ var myX2 = myPage.marginPreferences.left; var myX1 = myPage.marginPreferences.right; } else{ var myX1 = myPage.marginPreferences.left; var myX2 = myPage.marginPreferences.right; } var myY1 = myPage.marginPreferences.top; var myX2 = myPageWidth - myX2; var myY2 = myPageHeight - myPage.marginPreferences.bottom; return [myY1, myX1, myY2, myX2]; } -
Jacki Schklar
May 11, 2007 at 6:17 pmOh my, well how’s that for service? Thank you, and thank Ole…! Will try it next week. I got around the triplicate text in the plugin with a little extra work, but this is a task I’ll need to do on a whole bunch of files this year, so I will try to find the most efficient way.
You are saying to add this to the InDesign CS2 script folder, right? Just making sure…
Reply to this Discussion! Login or Sign Up