18 Replies Latest reply on Aug 21, 2015 11:33 AM by Shaunre

    Convert text to outlines even if it's in a group? [JS][CS6]

    Shaunre

      First I need to say this: I know about the whole "convert to outlines" controversy and "properly outlining text". But in this case, it must be done the unproper way, and for reasons you may never heard of but I can't waste time explaining. Please just understand that we can't do any alternatives to outlining the text in inD. We must have the text outlined in the document itself.

       

      Anyway, so I have this old javascript that I found here on the forums and modified it slightly so it converted the text on every single page.

       

      This worked great when I used it in conjunction with a script that ungrouped completely everything (as you may know you can't convert text to outlines unless it's ungrouped)... that is until I realized that some documents I was working with had group effects and they would be lost after ungrouping. Unfortunately there is no easy way to preserve the group effects without scripting.

       

      However, I couldn't find a script that ungrouped only my text or even that ungrouped only groups with no effects applied. There was this thread Beginner: help with ungroup script that had a user trying to create one to ignore groups with effects but it doesn't seem to have ever been properly completed.

       

      So here's what I'm hoping to do: below is the script I was using the convert all text to outlines (and also remove the original text frame).

      Could we modify this so it returns all text objects, not just ungrouped ones? I wish I could do it myself, but I only know how to do some very light modding of scripts. I greatly appreciate any help.

       

      myPage = app.activeDocument;

      for (j=myPage.textFrames.length- 1; j >= 0; j--){

          try{

              myPage.textFrames[j].createOutlines();

              myPage.textFrames[j].remove();

              }catch(e){}

          }

       

       

       

      EDIT: I found something here that may be of some use: app.activeDocument.allPageItems;

      The top answer says that "allPageItems is pretty much guaranteed to return all page items, of all kinds and persuasion, inside groups or other frames or whatnot."

       

      I thought I knew exactly what needed to be done, which is to add the ".AllPageItems" after app.activeDocument.

       

      However, when I run the script, I get a javascript error saying "undefined is not an object" on line 2.

      My ideas run out there.

        • 1. Re: Convert text to outlines even if it's in a group? [JS][CS6]
          Marc Autret Level 4

          Hi,

           

          What you need seems to be this:

           

          var a = app.activeDocument.allPageItems,
              t;
          
          while( t=a.pop() )
              {
              if( !(t instanceof TextFrame) ) continue;
              try{ t.createOutlines(true) } catch(_){}
              }
          
          

           

          @+

          Marc

          • 2. Re: Convert text to outlines even if it's in a group? [JS][CS6]
            G. Singelmann Level 3

            The safest way for you to go is something called "recursion".


            Like this:


            if ( app.documents ) main();
            
            
            function main() {
               
               handle_items( app.activeDocument.pageItems.everyItem().getElements() )
               
               function handle_items( items ) {
                  for (var n = 0; n < items.length; n++) {
                     var item = items[n];
                     if ( item.pageItems.length ) {
                        handle_items( item.pageItems.everyItem().getElements() );
                     }
                     if ( item.constructor.name == "TextFrame" ) {
                        item.createOutlines();
                     }
                  }
               }
            }
            
            
            
            • 3. Re: Convert text to outlines even if it's in a group? [JS][CS6]
              Laubender Adobe Community Professional & MVP

              Hi Shaun,

              maybe your case is more complicated than you think…

               

              Do you know, if any of the effects are on the text itself?

              (I do not speak about text frames, but formatted text)

               

              If yes, It could be hard to imposible to do what you like to do (preserving *exact* visual appearance after creating outlines).

               

              If not, we could convert the text to outlines, not the text frame and convert the text frame to a graphic object in case the formatting of insertion point one in the text frame is triggering any preflight tool that demands there should be no formatted text there.

               

              Note, that I am using a special ingredients for method createOutlines(), a special parameter, false, that would do a duplicate of the outlined text, then I will empty the text frame and finally I will convert the empty text frame to a graphic frame.

               

              Just to give you an example.

              Create a group with one single text frame and some other objects.
              Apply some effects to the group.

              Select the group and run the following ExtendScript snippet on it:

               

              var myGroup = app.selection[0];
              myGroup.textFrames[0].texts[0].createOutlines(false);
              myGroup.textFrames[0].contents = "";
              myGroup.textFrames[0].contentType = ContentType.UNASSIGNED;
              

               

              Here a screenshot:

               

              BeforeAndAfter-createOutlines.png

               

              I edited the names of the groups in the Layers Panel after running the script to show which is which.

               

              Uwe

              • 4. Re: Convert text to outlines even if it's in a group? [JS][CS6]
                Shaunre Level 1

                Interesting, I will try this tomorrow and report back. Thanks for helping!

                • 5. Re: Convert text to outlines even if it's in a group? [JS][CS6]
                  Shaunre Level 1

                  Looks promising enough. I'll try it tomorrow and let you know how it works for me. Thanks for writing that up!

                  • 6. Re: Convert text to outlines even if it's in a group? [JS][CS6]
                    G. Singelmann Level 3

                    FWIW: Marc's code is far more elegant than mine. Recursion as a concept is something you should know though, so: no harm done

                    • 7. Re: Convert text to outlines even if it's in a group? [JS][CS6]
                      Shaunre Level 1

                      There are no effects on text boxes if they contain actual text. There are, on rare occasions effects applied to only a text frame. I believe that the convert outlines skips over any text frames with no text so I have a good feeling your script will work as the set empty text boxes to unassigned  is includes and done last. Tomorrow morning I'll try that script you made and let you know what happens. Thanks for your help!

                      • 8. Re: Convert text to outlines even if it's in a group? [JS][CS6]
                        Laubender Adobe Community Professional & MVP

                        Hi Gerald,

                        running your snippet on my example (screenshot) is resulting in this.

                        No text frame, no drop shadow.

                        ResultUsingTextFrame-instead-of-text.png

                         

                        So I expanded your code with my idea using createOutlines() on the text instaed on the text frame:

                         

                        if ( app.documents ) main(); 
                        
                        function main() { 
                        
                            handle_items( app.activeDocument.pageItems.everyItem().getElements() )
                        
                            function handle_items( items ) {
                               
                                for (var n = 0; n < items.length; n++) { 
                                    var item = items[n]; 
                                    if ( item.pageItems.length ) { 
                                        handle_items( item.pageItems.everyItem().getElements() ); 
                                        }
                                   
                                    if ( item.constructor.name == "TextFrame" ) {
                        
                                        item.texts[0].createOutlines(false);
                                        item.contents = "";
                                        item.contentType = ContentType.UNASSIGNED;
                                        } 
                                    } 
                                }
                            }
                        

                         

                        Now it is ok for this example.

                        But there could be some pitfalls also in this method, because the resulting outline paths are not inside the group.

                         

                        Uwe

                        • 9. Re: Convert text to outlines even if it's in a group? [JS][CS6]
                          G. Singelmann Level 3

                          I like "there could be some pitfalls" in context with "converting text to outlines".

                           

                           

                          • 11. Re: Convert text to outlines even if it's in a group? [JS][CS6]
                            S Hopkins Adobe Community Professional

                            What you need to know about create outlines (using text frame as object):

                            If text frame is empty or can't convert content to outline, an error is thrown

                            Result of createOutlines is a list, not an object (as more than 1 text item coild be converted)

                            Original text item is deleted by default.

                            I tried the following with document having: drop shadow applied to frame that is part of group, text that is part of frame in group where other group item has drop shadow, text part of frame not in group with drop shadow applied.. Drop shadow and styling was preserved. This with InDesign CC 2015. My understanding is that groups work better in more recent versions of InDesign.

                            var a = app.activeDocument.allPageItems,  t; 

                            while( t=a.pop() )  {

                                if( !(t instanceof TextFrame) ) continue; 

                                try{ var outlineList = t.createOutlines(true) ;//removes original

                                    var thisItem = outlineList[0];//assumes only 1 item in frame

                                    //in case you want to style polygon created

                                    thisItem.fillColor = "Dark Red";

                                    thisItem.strokeWeight = "2 pt";

                                    thisItem.strokeColor = "Black";

                                } catch(_){

                                } 

                            }

                            • 12. Re: Convert text to outlines even if it's in a group? [JS][CS6]
                              Shaunre Level 1

                              Hi Laubender, I seem to be getting a java script error when trying the code. Says that "pageitems" is not a supported property. Similar issue when I try 's recursion script. Says pageitems is not a supported property.

                               

                              However, when I run Marc's script, and then your old script I found here Re: cleaning up text frames which sets all text boxes to "unassigned"

                              I get precisely the result I'm looking for, and also it is not an issue that the outlined text is outside of the group.

                               

                              Also I have no issue with needing two scripts for this but I would be happy with an "all-in-one" if you're up for making it!

                               

                              Lastly, am I allowed to mark more than one answer as correct?

                              • 13. Re: Convert text to outlines even if it's in a group? [JS][CS6]
                                Laubender Adobe Community Professional & MVP

                                Hm yes, speaking about pitfalls:

                                 

                                1. Anchored text frames (un-anchoring before creating outlines would be necessary, but doing so will provoke other problems when grouped; stacking order, effects …)

                                2. Text frames containing "white space" only (a case we should solve beforehand)

                                3. Text frames containing no contents (a case we should solve beforehand)

                                4. Effects on graphic frames stacked above text frames in the same group influence the appearance of formatted text below.

                                (E.g. drop shadows on formatted text)

                                 

                                 

                                I'm sure, I missed some others. :-(

                                 

                                Uwe

                                • 14. Re: Convert text to outlines even if it's in a group? [JS][CS6]
                                  Shaunre Level 1

                                  I thought marc's script would convert everything, even if it's anchored. Also 2 and 3 seem to be fixed for me with your script that converts all frames to unassigned. I'm not sure about 4 but that sounds like something that none of our documents would have. There are sometimes drop shadows on text but that seems to be on the text itself and preserved when converting to outlines. The document I tested everything on is what I would consider as "worst case scenario" in regards to the potential for losing attributes when needing to convert to outlines, and all went perfectly, except for our automatic page labels.

                                   

                                  I should have realized this before, but for some documents we have labels in the master page for automatic page numbers, and when we convert it to outlines we lose the page number and it reverts back the the "L" or "R"  as we have two master pages- one for each the Left page and one for the Right. I can't seem to find anyone else who has attempted to make a script that preserves these labels, perhaps by copying them from the master and applying them to the appropriate page and changing the text so the ending letter is replaced with the proper page number. Or maybe there could be an even simpler way. I tried to do some research on this but couldn't find any answers providing scripts, just people that provide the usual answer when someone asks about outlining text, which is to use the flattener method. Possible to Outline Automatic Page Numbers?

                                   

                                  It's probably a long shot but would it be possible to modify the outline script so labels on master pages are preserved?

                                   

                                  EDIT: Just discovered something that may make the script making fairly simple- When I copy the text box from the master layer, and paste it on to any given page, the number is automatically changed. This means that a simple paste in place on each page (or every other page) could be made and save a good chunk of time. I'm going to make a new thread about this as this is something that can be of great use to us beyond creating outlines.

                                   

                                  EDIT 2: Here is that thread I made if you are interested in helping with this other script: Paste in place on every other page? [JS] [CS6]

                                  • 15. Re: Convert text to outlines even if it's in a group? [JS][CS6]
                                    Laubender Adobe Community Professional & MVP

                                    Hi Shaun,

                                    just out of curiosity: Why don't you go the "easy" way with exporting to PDF or printing to PostScript (distilling to PDF) and you using the"transaparency-trick-plus-flattening method" for creating outlines of the text at output stage? I do not want to question any workflow, just want to know, because there other pitfalls with creating outlines as well, that could be avoided in exporting to PDF or printing to PostScript.

                                     

                                    5. (You already mentioned it) Automatic page naming and numbering

                                    6. Using text variables of any kind

                                    7. Using underlines, strike through on text will be missing after conversion

                                    8. Using paragraph shading (new feature in CC-2015), the shading will not survive outlining the text

                                    9. Using tables will create the outlines, but the table structure will not be converted to paths, it will remain a table with formatted insertion points *

                                    10. Using strokes on text => will always convert to center position on the path, even when set aligned to outside of path when used with live text

                                    11. Using automatic bullet paragraph numbering *

                                    12. Using Footnotes *

                                     

                                    Not tested extensively by me. Details could vary, but I'm sure that after outlining text, remnants will be left over that you might not like at all.

                                    And I think, there are still more pitfalls I did not mention here.

                                     

                                    Uwe

                                    • 16. Re: Convert text to outlines even if it's in a group? [JS][CS6]
                                      Shaunre Level 1

                                      It's kind of a long story, but basically what we are doing is converting some old indesign documents to a different size, and adjusting the contents to be balanced in the best possible way (and also re-adusting the document codes and watermarks to be in their proper location), and then creating a copy of the document which has the text converted to outlines which is used by various automation tools to adjust things like color specified by the customer which cannot be done when the text is in it's original form. So not printer issues, but automation and my extent of my knowledge on that pretty much ends there unfortunately.


                                       

                                      You've helped us immensely with our process and I'm thankful especially with how you've made note of many of the pitfalls, but it does not seem like we can work around the outlining. The good news is that we also have great quality control which can make sure that if there are any discrepancies after outlining text, they are caught.

                                      • 17. Re: Convert text to outlines even if it's in a group? [JS][CS6]
                                        Shaunre Level 1

                                        Hey Marc, quick question- can you make it so the script is applied to just one page? i'm having a weird problem where a particular document crashes Indesign after running the script. I'm thinking that there's a limit to how much text can be converted at once and the nearly 50 page document I'm trying to convert to outlines has quite a lot of text.

                                         

                                        Thanks!

                                        • 18. Re: Convert text to outlines even if it's in a group? [JS][CS6]
                                          BSKTCreation Level 2

                                          If you just want 1 page processed then add the page to the first line, so for the first page it would be:

                                           

                                          app.activeDocument.pages.item(0).allPageItems

                                           

                                          Brett

                                          • 19. Re: Convert text to outlines even if it's in a group? [JS][CS6]
                                            Shaunre Level 1

                                            Sorry, I should have made it more clear, but I wanted it to apply to the active page.

                                             

                                            I ended up getting it to work though:

                                             

                                            var a = app.activeWindow.activePage.allPageItems,
                                            t;
                                            while( t=a.pop() )
                                            {
                                            if( !(t instanceof TextFrame) ) continue;
                                            try{ t.createOutlines(true) } catch(_){}
                                            }

                                             

                                             

                                            EDIT: I still have issues with indesign crashing on some pages. It doesn't make sense. Anyone have any ideas?