9 Replies Latest reply on Mar 15, 2016 4:14 AM by tpk1982

    Flowing word file through scripting

    tpk1982 Level 4

      Hi,

       

      I am trying to flow word document using script. The objective of this script is choosing only doc file and ignore all other text formats like rtf, docx etc

       

      The following code i wrote is choosing the doc file. Now i need to flow the choosen word file. Can anyone help please?

       

      function filterFiles(file){
           if(file.name.match(/\.doc$/)){return true}
           return false
      }
      file = File.openDialog ("Choose the file" , filterFiles, false );
      

       

      Regards,

      Karthi

        • 1. Re: Flowing word file through scripting
          tpk1982 Level 4

          Hi,

           

          Any suggestions please?

           

          Thanks,

          Karthi

          • 2. Re: Flowing word file through scripting
            Chinnadk Level 4

            Try this,

             

            var doc = app.activeDocument, left, right, bottom, top;
            var width = doc.documentPreferences.pageWidth;
            var height = doc.documentPreferences.pageHeight;
            var file = File.openDialog("Choose the file", "*.doc", false);
            margins(doc.pages.item(0))
            var txfm = doc.pages.item(0).textFrames.add({geometricBounds:[top,left,height-bottom,width-right]});
            txfm.place(file)
            
            function margins(page)
            {
                top = page.marginPreferences.top,
                bottom = page.marginPreferences.bottom;
                if(page.documentOffset % 2 != 1)
                {
                        left = page.marginPreferences.left;
                        right = page.marginPreferences.right;
                    }
                else
                {
                        right = page.marginPreferences.left;
                        left = page.marginPreferences.right;
                    }    
                }
            

             

            Regards,

            Chinna

            • 3. Re: Flowing word file through scripting
              tpk1982 Level 4

              Hi Chinna,

               

              Thanks for your help. But it shows all doc and docx files. Can i add my function in your script?

               

              Regards,

              Karthi

              • 4. Re: Flowing word file through scripting
                Peter Kahrel Adobe Community Professional & MVP

                Is there any reason why you don't use InDesign's smart text reflow?

                • 5. Re: Flowing word file through scripting
                  tpk1982 Level 4

                  Hi Peter/Chinna,

                   

                  Sorry for the delay in response. I tried smart text reflow but it wont work. May i know where i missed? In line 15 i used smart text reflow code.

                   

                  function filterFiles(file){ 
                      if(file.name.match(/\.doc$/)){return true} 
                      return false 
                  } 
                  file = File.openDialog ("Choose the file" , filterFiles, false ); 
                  
                  
                  var doc = app.activeDocument, left, right, bottom, top; 
                  var width = doc.documentPreferences.pageWidth; 
                  var height = doc.documentPreferences.pageHeight; 
                  //var file = File.openDialog("Choose the file", "*.doc", false); 
                  margins(doc.pages.item(0)) 
                  var txfm = doc.pages.item(0).textFrames.add({geometricBounds:[top,left,height-bottom,width-right]}); 
                  txfm.place(file) 
                  doc.textPreferences.smartTextReflow=true; 
                  
                  
                  function margins(page) 
                  { 
                      top = page.marginPreferences.top, 
                      bottom = page.marginPreferences.bottom; 
                      if(page.documentOffset % 2 != 1) 
                      { 
                              left = page.marginPreferences.left; 
                              right = page.marginPreferences.right; 
                          } 
                      else 
                      { 
                              right = page.marginPreferences.left; 
                              left = page.marginPreferences.right; 
                          }     
                      } 
                  

                   

                   

                  Regards,

                  Karthi

                  • 6. Re: Flowing word file through scripting
                    Peter Kahrel Adobe Community Professional & MVP

                    That single line of code is not necessarily enough. You need to set up the document correctly. Once your document is ok, all you need to do is drop the text in the text frame on the first page and InDesign will do the rest for you.

                    • 7. Re: Flowing word file through scripting
                      tpk1982 Level 4

                      Hi Peter,

                       

                      Yes i tried but it is not working, below screenshot shows the preference setup of my document.

                       

                      Screen Shot 2016-03-15 at 3.18.21 PM.png

                       

                      Regards,

                      Karthi

                      • 8. Re: Flowing word file through scripting
                        Peter Kahrel Adobe Community Professional & MVP

                        That's not the only requirement. Your document needs two pages with a text frame on each page, and the frames have to be threaded. For further details see any documentation.

                        • 9. Re: Flowing word file through scripting
                          tpk1982 Level 4

                          Thanks Peter