11 Replies Latest reply on Jun 28, 2017 1:34 AM by Theo Duijkers

    Script for export all text in single rtf file?

    Belimisimus Level 1

      Hi!

       

      I need to export all storys from indd document to a single rtf file. Is there avaible some free script for CS4 which can do that?

        • 1. Re: Script for export all text in single rtf file?
          Kasyan Servetsky Level 5

          Check out these scripts:

          Export all text, Batch-convert/export documents by Peter Kahrel and Rorohiko's TextExporter plug-in.

           

          Kasyan

          2 people found this helpful
          • 2. Re: Script for export all text in single rtf file?
            Belimisimus Level 1

            I try Rorohiko's 'TextExporter' plug-in and it is very useful but unfortunally it's not free.
            On the other way, your script 'Export all text' has fewer options but for my needs it's working very fine. Thanxs for helping!

            Do you perhaps have this script written in VB?

            • 3. Re: Script for export all text in single rtf file?
              Kasyan Servetsky Level 5
              Do you perhaps have this script written in VB?

               

              There is a script that comes with InDesign — ExportAllStories.vbs — located in \Scripts\Scripts Panel\Samples folder

               

              Kasyan

              2 people found this helpful
              • 4. Re: Script for export all text in single rtf file?
                Belimisimus Level 1

                This script export every story in seperate file. I don't know how to merg all that files into one document.

                And one more question, If I understand, your script export storys ordered by ID of text frame, is it possible to export storys on page by the location of text frame?

                • 5. Re: Script for export all text in single rtf file?
                  Kasyan Servetsky Level 5

                  If memory serves me right, the script you downloaded from my site is a little reworked version of the pre-installed with ID sample script.

                   

                  ...is it possible to export storys on page by the location of text frame?

                   

                  It depends on the layout: I think for simple layout it's possible — the script can check geometric/visible bounds of each text frame from left to right and from top to bottom to sort them in the proper order. Then export each text frame's parentStory, remembering the stories that have been already exported to an array --  e.g. by their IDs -- to avoid exporting the same story several times (for threaded textframes). Or may be just export text on frame by frame basis — I can't say exactly which approach is better without seeing your layout.

                   

                  Why do you want to edit VB script? JS works both on Mac and PC.

                  • 6. Re: Script for export all text in single rtf file?
                    Belimisimus Level 1
                    Why do you want to edit VB script? JS works both on Mac and PC.

                     

                    I'm pretty green about VB and JS and let say that I know VB little better than JS and JS i don't know at all.

                    Never mind i'll try to learn understanding JS.

                     

                    I can't say exactly which approach is better without seeing your layout.

                     

                    Let say that you have indd with 200 pages and on every page you have 10 seperate (not linked) text boxes. I would like to export all text as they appear by pages. It is not nessesery to be from top to bottom, or from left to right only that they are not mixed within pages.

                    Only limitation of your script is that it export text by ID of text frame, so the last created text frame in InDesign will be exported and moved at the end of rtf file.

                    • 7. Re: Script for export all text in single rtf file?
                      Kasyan Servetsky Level 5

                      if(app.documents.length != 0){
                           if(app.documents.item(0).stories.length != 0){
                                myGetFileName(app.documents.item(0).name);
                           }
                      }
                      //========================= FUNCTIONS ===========================
                      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 myPage, myStory;
                           var myExportedStories = [];
                           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 (var i = 0; i < myDocument.pages.length; i++) {
                                myPage = myDocument.pages.item(i);
                                for (var t = 0; t < myPage.textFrames.length; t++){
                                     myStory = myPage.textFrames[t].parentStory;
                                     if (!IsInArray(myStory.id, myExportedStories)) {
                                          //Export the story as tagged text.
                                          myStory.exportFile(ExportFormat.taggedText, myTempFile);
                                          myExportedStories.push(myStory.id);
                                          //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(i != 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";
                                               }
                                          }
                                     } // if not exported
                                } // for text frames
                           } // for pages
                           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];
                      }
                      //--------------------------------------------------------------------------------------------------------------
                      function IsInArray(myString, myArray) {
                           for (x in myArray) {
                                if (myString == myArray[x]) {
                                     return true;
                                }
                           }
                           return false;
                      }
                      //--------------------------------------------------------------------------------------------------------------

                      This is a revised version of the script --  not totally tested.

                       

                      Kasyan

                      • 8. Re: Script for export all text in single rtf file?
                        Belimisimus Level 1

                        Kasyan, can I marry you?

                         

                        You save me a lot of work time!

                        Once more thanxs for helping, that was exactly what I was looking for.

                        • 9. Re: Script for export all text in single rtf file?
                          Kasyan Servetsky Level 5

                          Kasyan, can I marry you?

                          You are seven years late — I'm already hitched.

                           

                          Glad it works for you. BTW, it took only a couple of minutes to revise it.

                           

                          Kasyan

                          • 10. Re: Script for export all text in single rtf file?
                            Terkelsen

                            I have been using this great script to export all text from an InDesign document for a while. However, I've run into the problem, that text from text boxes that are part of a group, is not included in the exported text.

                             

                            Does anybody know how to overcome this problem?

                            • 11. Re: Script for export all text in single rtf file?
                              Theo Duijkers

                              Hi Kasyan, very pleased that I finally found your script, it still works with CC2017. I do het lots of error messages along the way during export, but the RTF export text is very usable.

                              Any chance you have updated this script?