8 Replies Latest reply on Feb 7, 2016 1:23 PM by Laubender

    How do I place a indd file - just the text?

    Schmaltzkopf

      Hi there.

      This is a snippet of my code.

       

      var tfiImport = File("C:/Users/Me/Documents/YS/Exported Stories/YS_full_pg.indd");
              tfYS[0].insertionPoints.item(-1).place(tfiImport);
      
      

       

      I am trying to import a indd file into a pre-existing text-frame. The frame becomes overset, because the indd file is placed in actual size.

      The indd is a text file with various styles applied. I just want to grab that text with the styles and place it in my text-frame, auto-flowing as necessary.

      How can I do that?

       

      Any help would be appreciated.

        • 1. Re: How do I place a indd file - just the text?
          Loic.Aigon Adobe Community Professional

          Hi,

          As far as I know, you can't just grab text contents by targeting an InDesign document. Once that said your options are numerous. You can either export all text contents to rtf or text (some available scripts at rorohiko I think), or if XML was used, export/import XML. Eventually you can think of a script that would open file, get contents and retrieve.

          Loic

          • 2. Re: How do I place a indd file - just the text?
            Laubender Adobe Community Professional & MVP

            Hi SK,

            you'd open that InDesign document and duplicate the text to your insertion point.


            Two documents are open.

            The insertion point where you want to "place" the formatted text is selected.

            There is at least one text frame with one paragraph in the document where you want to duplicate from.

             

            Example:

             

            var targetDocument = app.documents[0]; // The active document
            var sourceDocument = app.documents[1];
            
            var targetInsertionPoint = app.selection[0].insertionPoints[0];
            
            sourceDocument.textFrames[0].paragraphs[0].duplicate(LocationOptions.AFTER,targetInsertionPoint);
            

             

            Example:

            To duplicate the whole formatted text of a story where you know one text frame of that story:

             

            sourceDocument.textFrames[0].parentStory.texts[0].duplicate(LocationOptions.AFTER,targetInsertionPoint);
            

             

            Look up the Text Object in the DOM documentation and its methods.

            Adobe InDesign CS6 (8.0) Object Model JS: Text

             

            Also app.open() method:

            Adobe InDesign CS6 (8.0) Object Model JS: Application

             

            Uwe

            • 3. Re: How do I place a indd file - just the text?
              [Jongware] Most Valuable Participant

              (Only very tangentially related to your question. Feel free to ignore   (although I do have some good reasons to ask).)

               

              There is no separate single "text" in an InDesign document, there may be several (unconnected) stories. Some of them may reside on master pages, in separated text frames with only a page number and/or header. Some of them may be in separate text frames, as a figure caption, or as an entire table. How do you select which text stories to import?

               

              Text may be made non-printable by placing it inside a textframe and then setting that frame to 'nonprinting'. Should it get imported anyway? (Complicating the matters: a single story that runs over 2 text frames. The first one is set to nonprinting, the second one is not. What should be imported?)

               

              Cross references can point to targets inside the same story (which is not a problem) but also to a target in another one (which is). Replace by placeholders or by plain text - as if "converted to text"?

               

              Conditional text: should the original document's settings for which one(s) are visible be honored (so you only "get what you see"), or should all of it be imported, with conditions and all?

               

              Styles: similar to the Word import filter: should their original definitions be imported, or should it use the same name with your local definitions, or should imported duplicate style names automatically get renamed?

              • 4. Re: How do I place a indd file - just the text?
                Trevorׅ Adobe Community Professional

                In addition to Uwe's method which I would consider as correct you might want to use the importStyles method and generate the text by script.

                • 5. Re: How do I place a indd file - just the text?
                  Schmaltzkopf Level 1

                  Thank you. I guess there are a lot of possibilities.

                   

                  1. I have many text-frames in my source doc, but only want to duplicate 3 stories. The stories each appear on each page (story 1 spans pages 1-7, story 2 spans pages 1-7, and story 3 spans pages 1-7). I guess I target the first frame of each one.

                  2. At this point I am not yet dealing with non-printables or cross-references.

                  3. Conditional-text - duplicate with them.

                  4. Styles - I would like to import them with their original definitions, but (maybe) rename them.

                   

                  Also, I opened the file:

                   

                  var fileRef = new File("C:/Users/Me/Documents/YS/Exported Stories/YS_full_pg.indd");

                      app.open(fileRef);

                   

                  and am ready to execute your "var targetInsertionPoint = app.selection[0].insertionPoints[0];", but I am not sure how to make a selection with my script.

                  • 6. Re: How do I place a indd file - just the text?
                    Laubender Adobe Community Professional & MVP

                    You need no selection to target an insertion point. That was just an example.

                    You could add a new text frame and use it's only insertion point like that:

                     

                    var newTextFrame = app.documents[0].pages[0].textFrames.add(
                    {
                        geometricBounds : app.documents[0].pages[0].bounds    // Array of 4 values for the corners coordinates [ y1 , x1 , y2 , x2 ] of the frame
                    }
                    );
                    
                    var insertionPoint = newTextFrame.parentStory.insertionPoints[0];
                    

                     

                    Or you could use the last insertion point of that story, if you start with a text frame, that already contains text:

                     

                    var newTextFrame = app.documents[0].pages[0].textFrames.add(
                    {
                        geometricBounds : app.documents[0].pages[0].bounds,
                        contents : "Hello World!"+"\r"
                    }
                    );
                    
                    var insertionPoint = newTextFrame.parentStory.insertionPoints[-1];
                    

                     

                    Note: I'm using newTextFrame.parentStory.insertionPoints[-1] instead of newTextFrame.insertionPoints[-1], because I want to make sure to use the last insertion point of the story, not the text frame. The text frame could be overset.

                     

                    Uwe

                    • 7. Re: How do I place a indd file - just the text?
                      Schmaltzkopf Level 1

                      "sourceDocument.textFrames[0].paragraphs[0].duplicate(LocationOptions.AFTER,targetInsertionPoint);"

                       

                      how do I know which textframe InDesign sees as textFrames[0], textFrames[1], and textFrames[2]

                      • 8. Re: How do I place a indd file - just the text?
                        Laubender Adobe Community Professional & MVP

                        It depends.
                        You could identify it by a Text or Grep search.
                        What ever fits your contents. The criteria will depend of what you know about that document.

                         

                        A story is composed out of textContainers (array), that represent the text frames and/or the text path pageItems where the story flows through.

                        textContainers[0] is the first one in the flow. That will not mean it is the first in geometrical order. You could start a story on page 20 and continue on page 1.

                         

                        We don't know anything about your documents, so it's hard to suggest the best procedure.

                         

                        Uwe