9 Replies Latest reply on Jul 6, 2010 12:09 AM by aanavaras

    Export-RTF is not working in CS3

    aanavaras Level 1

      Dear Guys,

       

      I'm new to this field.

       

      With reference of InDesign CS3 scripting guides i exported TXT output from an InDesing Document.

      But i cannot export RTF Output.

       

      Can anyone help me on this?

       

       

      Thanks

       

      SaRaVaNaN.N

        • 1. Re: Export-RTF is not working in CS3
          Kasyan Servetsky Level 5
          var doc = app.activeDocument;
          var story = doc.stories[0];
          var rtfFile = new File("~/Desktop/Test.rtf");
          story.exportFile(ExportFormat.RTF, rtfFile);
          
          1 person found this helpful
          • 2. Re: Export-RTF is not working in CS3
            aanavaras Level 1

            I'm so Sorry Friend,

             

            Its my mistake only.

            Actually i want to do this in VB6.


            Here is my Code below:


                InDsgn_Path1 = "c:\Test.indd"
                Set myInd = CreateObject("InDesign.Application.CS3")
                myInd.ScriptPreferences.UserInteractionLevel = idNeverInteract
                myFile = InDsgn_Path1
                myind.Open myFile, True
                Set myIndFile = myInd.ActiveDocument
                myFile = Replace(myFile, ".indd", ".rtf")
                myIndFile.Export idExportFormat.idRTF, myFile, False
                myIndFile.Close


            But this is not working...


            ERROR:

            Run-time Error '25398'

            The Specified object does not support the desired export format.


            Sorry Again. Please help me...

            • 3. Re: Export-RTF is not working in CS3
              [Jongware] Most Valuable Participant

              The error message is correct:

               

              Set myIndFile = myInd.ActiveDocument
                  myFile = Replace(myFile, ".indd", ".rtf")
                  myIndFile.Export ...

               

              since you cannot export an entire document to RTF, only per story, as Kasyan shows. It's no different from the UI itself.

              • 4. Re: Export-RTF is not working in CS3
                aanavaras Level 1

                Thanks Jongware.

                 

                Can you give me a Sample code to export All Stories to a RTF?

                 

                 

                Thanks in Advance.

                • 5. Re: Export-RTF is not working in CS3
                  [Jongware] Most Valuable Participant

                  ExportAllStories.jsx is one of the sample scripts which get installed by default in your Scripts panel, under Application -> Samples -> Javascript. The file "InDesign CS3 Sample Scripts Readme.pdf" contains some general information about the scripts in this folder.

                  • 6. Re: Export-RTF is not working in CS3
                    Kasyan Servetsky Level 5

                    Here is a sample showing how to export RTF in VB:

                    Set myInDesign = CreateObject("InDesign.Application.CS3")
                    Set myDoc = myInDesign.Open("C:\Test.indd")
                    Set myStory = myDoc.Stories.Item(1)
                    myStory.Export idExportFormat.idRTF, "C:\Test.rtf"
                    myDoc.Close
                    

                     

                    Here is a script by Peter Kahrel that exports all text as RTF.

                    1 person found this helpful
                    • 7. Re: Export-RTF is not working in CS3
                      aanavaras Level 1

                      Kasyan Servetsky, Thanks.


                      Your code is working fine. But its exporting each stories into individual files.

                      Is there any possibilities to export all stories into One Single RTF File?


                      This is what i want actually.

                      Can anyone Help me.?

                      • 8. Re: Export-RTF is not working in CS3
                        Kasyan Servetsky Level 5

                        I remade ExportAllText.jsx script a little (from InDesign CS3 guide scripts package).

                        Now it exports all stories into a single rtf file: C:\Exported Text.rtf

                        While running the script creates and deletes a temporary file: C:\Temporary File.txt

                         

                        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 myTempFile = new File("/c/Temporary File.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, 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";
                                       }
                                  }
                             }
                             myNewStory.exportFile(ExportFormat.RTF, File("/c/Exported Text.rtf"));
                             myNewDocument.close(SaveOptions.no);
                             
                             try {
                                  myTempFile.remove();
                             }
                             catch(e){}
                             
                             alert("Done.");
                        }
                        
                        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];
                        }
                        
                        • 9. Re: Export-RTF is not working in CS3
                          aanavaras Level 1

                          Thank you Kasyan Servetsky.

                           

                          Its working fine with some changes & its very useful to me...

                           

                          Thanks a lot again.