8 Replies Latest reply on Mar 28, 2016 9:25 PM by Sudha K

    Report Writing...

    Sudha K Level 1

      Hi,

       

           When writing the contents as report, report is generated as empty.  Because the contents have some character (XML Tags ie., ::).  So Could not able to write the contents.

       

           I have used find and replace but its not removed.  How can I get the contents to write report.

       

       

       

           Screen shot 2016-03-24 at 9.36.10 AM.png

        • 1. Re: Report Writing...
          pixxxel schubser Level 5

          Is this a scripting question?

          Please show the relevant part of your code and at the best an example IDML file.

          • 2. Re: Report Writing...
            Laubender Adobe Community Professional & MVP

            Hi Sudha,

            the contents should be writable. Even when XML tags are present.
            However, they would perhaps reflect as additional white space in the text file.

             

            If you want get rid of them, search for <FEFF> characters with Text Search/Replace in InDesign.

            Or use RepExp with ExtendScript and replace the special characters before writing the report to a text file.

             

            Here an example.

            Select some text with XML tags in InDesign and run the snippet:

             

            var myRegEx = "\\x{FEFF},g,\"\"";
            var myString = app.selection[0].texts[0].contents;
            
            alert(myString.replace(myRegEx));
            

             

             

            Uwe

            • 3. Re: Report Writing...
              Sudha K Level 1

              Hi,

               

                  Thank you....  Its still generate an empty csv for me. Below is the used code.

               

              var myRegEx = "\\x{FEFF},g,\"\""; 

              var myString = app.selection[0].texts[0].contents; 

              var myString1 = myString.replace(myRegEx);

              alert(myString.length + " = " + myString1.length)

              reportPath = app.activeDocument.filePath.fsName;

              reportName = app.activeDocument.name.replace(".indd",".csv");

              writeReport(reportPath, reportName, myString);   

               

              function writeReport(fPath, fName, str)

              {

                  var rept = new File(fPath+"/"+fName );       

                  alert("rept " +rept)

                  rept.open("w");

                  var wBool = rept.write(str);       

                  rept.close();

              }

               

              Contents length is same before and after process of regex.

               

               

              - Sudha K

              • 4. Re: Report Writing...
                Laubender Adobe Community Professional & MVP

                Hi Sudha,

                sorry, I suggested the wrong method.

                 

                We have to inspect every single character in the selection.

                 

                var stringArray = app.selection[0].characters.everyItem().contents;
                alert(stringArray.length);
                
                for(var n=0;n<stringArray.length;n++)
                {
                    if(stringArray[n].charCodeAt() == 65279){stringArray[n] = ""};
                };
                
                var string = stringArray.join("");
                
                alert(string.length);
                

                 

                Uwe

                • 5. Re: Report Writing...
                  Laubender Adobe Community Professional & MVP

                  No, my second suggestion is not so clever.

                  Enumerations of special characters will throw an error.
                  Like FORCED_LINE_BREAK or EM_DASH etc.pp.

                   

                  Property contents can contain string and special characters:

                  Adobe InDesign CS6 (8.0) Object Model JS: Text


                  Because creating the array out of the contents of single characters the loop will throw an error, if an enumerable special character is hit.

                  If we ignore the enumerable special character, the meaning of text in the result string will change. If we let them through to the result string, "FORCED_LINE_BREAK" will be literally added. Not good at all. Just tested that with a forced line break in the selected text:

                   

                  var stringArray = app.selection[0].characters.everyItem().contents; 
                  alert(stringArray.length); 
                  
                  for(var n=0;n<stringArray.length;n++) 
                  { 
                  
                      $.writeln(stringArray[n]);
                      //if(stringArray[n].charCodeAt() == 65279){stringArray[n] = ""};
                  
                  }; 
                  
                  var string = stringArray.join(""); 
                  
                  alert(string.length);
                  alert(string);
                  

                   

                   

                  So we can use a different strategy then:

                  Split and join the contents of the selection with the special character.
                  That should be most effective. Forced line breaks are not touched.

                   

                  stringOfTextContents = app.selection[0].contents;
                  $.writeln(stringOfTextContents.length);
                  resultString = stringOfTextContents.split("\uFEFF").join("");
                  $.writeln(resultString.length);
                  

                   

                   

                  Uwe

                  • 6. Re: Report Writing...
                    Laubender Adobe Community Professional & MVP

                    If you want to omit anchored objects special characters as well, throw in another line:

                     

                    stringOfTextContents = app.selection[0].contents;
                    $.writeln(stringOfTextContents.length);
                    
                    // XML tags, Index markers, Notes markers
                    stringOfTextContents = stringOfTextContents.split("\uFEFF").join("");
                    
                    // Anchored object markers
                    stringOfTextContents = stringOfTextContents.split("\uFFFC").join("");
                    
                    $.writeln(stringOfTextContents.length);
                    $.writeln(stringOfTextContents);
                    

                     

                    Hope, that helps.
                    Uwe

                    • 7. Re: Report Writing...
                      Laubender Adobe Community Professional & MVP

                      After testing a bit, I can confirm, that special characters in InDesign formatted text like

                       

                      1. XML tag markers, Index markers, Notes markers: "\uFEFF"

                      2. Anchored object markers: "\uFFFC"

                       

                      will lead to empty text files, if the contents of text is used for writing the text files.

                      There could be other special characters, that would do the same. Maybe check for table special characters…

                       

                      Here a snippet that successfully is writing selected text with XML markers and anchored objects to a text file:

                       

                      var contents = app.selection[0].texts[0].contents;
                      $.writeln(contents.length);
                      var stringOfTextContents = contents.split("\uFEFF").join("").split("\uFFFC").join("");
                      $.writeln(stringOfTextContents.length);
                      
                      reportPath = app.activeDocument.filePath.fsName;
                      reportName = app.activeDocument.name.replace(".indd",".csv");
                      
                      writeReport(reportPath, reportName, stringOfTextContents); 
                      
                      
                      function writeReport(fPath, fName, str)
                      
                      {
                          var rept = new File(fPath+"/"+fName );     
                          //alert("rept " +rept)
                          rept.open("w");
                          var wBool = rept.write(str);     
                          rept.close();
                      
                      }
                      

                       

                      Case closed, I think.

                       

                      Uwe

                      • 8. Re: Report Writing...
                        Sudha K Level 1

                        Hi Uwe,

                         

                            Thank you so much... Its working....

                         

                            Can We call Script like Indesign or Acrobat Scripting using java? Without the help of applescript??