5 Replies Latest reply on Mar 12, 2014 12:24 AM by BEGINNER_X

    Anybody can help me for RTF conversion?

    hasvi Level 1

      Anybody can help me for RTF conversion for selected text frames only in Indesign by script

        • 1. Re: Anybody can help me for RTF conversion?
          BEGINNER_X Level 3

          Hi Hasvi,

           

          May the below code is useful, but ensure please select the text, not textframes.

           

           

          var myDoc = app.activeDocument;
          
          var myDocPath = myDoc.filePath;
          
          var myDocName = myDoc.name.split(".indd").join(".rtf")
          
          var mySelection = app.selection[0].contents;
          
          //~ alert("mySelection: " + mySelection)
          
          myFile = new File(myDocPath + "/" + myDocName);
          
          app.selection[0].exportFile(ExportFormat.rtf, myFile);
          

           

           

          Thanks

          Siraj

          • 2. Re: Anybody can help me for RTF conversion?
            hasvi Level 1

            Hi thanks for your swift reply, but I need RTF format with paragraph style name and content as like below:

             

            H1 => Introduction

            TX => Used for HIV infection in combination with other antiretroviral drugs

            ....

             

            Is this possible?

            • 3. Re: Anybody can help me for RTF conversion?
              BEGINNER_X Level 3

              Hi Hasvi,

               

              May this below coding used for the selection of particular contents or paragraphs.

               

              If you need a texFrame contents, then you have to use loop concept.

               

              var myDoc = app.activeDocument;
              
              var myDocPath = myDoc.filePath;
              
              var myDocName = myDoc.name.split(".indd").join(".rtf")
              
              var myPStyles = app.selection[0].paragraphs[0].appliedParagraphStyle.name;
              
              var mySelection = app.selection[0].contents;
              
              var myFinal = myPStyles + "\t\t" + mySelection;
              
              alert("myFinal: " + myFinal)
              
              var myTextFile = new File(myDocPath + "/" + myDocName);
              
              myTextFile.open("w")
              
              myTextFile.write(myFinal)
              
              myTextFile.close();
              
              
              alert("Process Completed")
              

               

              Thanks

              Siraj

              • 4. Re: Anybody can help me for RTF conversion?
                hasvi Level 1

                Hi its nice

                But I want it should be run for whole document. Not only for selection, is this possible?

                app.selection[0]

                 

                thank you again

                • 5. Re: Anybody can help me for RTF conversion?
                  BEGINNER_X Level 3

                  Hi Hasvi,

                   

                  May the below code helpful for you, Kindly check

                   

                   

                  var myDoc = app.activeDocument;
                  
                  var myDocPath = myDoc.filePath;
                  
                  var myDocName = myDoc.name.split(".indd").join(".txt")
                  
                  
                  var myParas = app.activeDocument.stories.everyItem().paragraphs.everyItem().getElements();
                  
                  myArray = new Array();
                  
                  alert("myParas: " + myParas.length)
                  
                  for(i=0; i<  myParas.length; i++)
                  {
                      
                  var myPStyles = myParas[i].appliedParagraphStyle.name;
                  
                  var mySelection = myParas[i].lines[0].contents;
                  
                  var myFinal = "PStyle: " + myPStyles + "\r" + "FirstLine: " + mySelection + "\r\r";
                  
                  
                  myArray.push(myFinal)
                  
                  }
                  
                  alert("myArray: " + myArray)
                     
                  var myTextFile = new File(myDocPath + "/" + myDocName);
                  
                  myTextFile.open("w")
                  
                  myTextFile.write(myArray)
                  
                  myTextFile.close();
                    
                  alert("Report Generated in Document Location")
                  

                   

                  If my reply helpful for you, then please click Helpful or Correct answer.

                   

                  It will motivate all forum members.

                   

                  Thanks

                  Siraj