1 Reply Latest reply on Jul 3, 2017 6:49 AM by jb_alvarado

    Continue overflow Text on new page

    jb_alvarado Level 1

      Hello everybody,

      from this forum I have found a script with that it is possible to expand overflowing text on new pages.

       

      I my case it not work correctly, because I have more the one textframes on the starting page and I also want to add a text frame on ever new page on top.

       

      At the moment my script looks like this:

       

      var storyTitle = "Hello I'm a title!"
      
      var myDocument = app.documents.item(0);
      var myDoc = app.activeDocument;
      var myFrames = app.selection[0].parent;
      
      while (myFrames.overflows === true) {
          var myNewPage = myDoc.pages.add();
      
          // add Page header
          myTitleFrame = myNewPage.textFrames.add();
          myTitleFrame.contents = storyTitle;
          myTitleFrame.geometricBounds = ["0mm", "0mm", "4.98mm", "148mm"];
          myTitleFrame.move([148, 8.62]);
      
          var myMargin = myNewPage.marginPreferences;
          var myBounds = [myMargin.top, myMargin.left, myDoc.documentPreferences.pageHeight - myMargin.bottom, myDoc.documentPreferences.pageWidth - myMargin.right];
          var myOldRuler = myDoc.viewPreferences.rulerOrigin;
          myDoc.viewPreferences.rulerOrigin = RulerOrigin.pageOrigin;
          with(myDoc.pages[-1].textFrames.add()) {
              geometricBounds = myBounds;
              if (myDoc.pages[-2].textFrames.length > 2) {
                  previousTextFrame = myDoc.pages[-2].textFrames[myDoc.pages[-2].textFrames.length - 1];
              } else {
                  previousTextFrame = myDoc.pages[-2].textFrames[1];
              }
              textFramePreferences.textColumnCount = 2;
              textFramePreferences.textColumnGutter = 5;
          }
          myDoc.viewPreferences.rulerOrigin = myOldRuler;
      }
      

       

      My problem is, this code is not working correctly. I'm not sure that the index on line 23 will be always correct. And the index on line 25 is for sure not correct on later pages.

       

      Can you help me here?

       

      Regrads

      Jonathan

        • 1. Re: Continue overflow Text on new page
          jb_alvarado Level 1

          I think, this here works, at least on my test file.

           

          var storyTitle = "Hello I'm a title!"
          
          var myDocument = app.documents.item(0);
          var myDoc = app.activeDocument;
          var myFrames = app.selection[0].parent;
          var myIndexStart = app.selection[0].parentTextFrames[0].index;
          
          while (myFrames.overflows === true) {
              var myNewPage = myDoc.pages.add();
              myNewPage.appliedMaster = myDoc.masterSpreads.item("A-Text");
          
              // add Page header
              myTitleFrame = myNewPage.textFrames.add();
              myTitleFrame.contents = storyTitle;
              myTitleFrame.geometricBounds = ["0mm", "0mm", "4.98mm", "148mm"];
              myTitleFrame.move([0, 8.62]);
              myTitleFrame.textFramePreferences.textColumnCount = 1;
              myTitleFrame.texts[0].appliedParagraphStyle = myDocument.paragraphStyleGroups.item("Meist genutzte").paragraphStyles.item("Seiten Kopf");
          
              var myMargin = myNewPage.marginPreferences;
              var myBounds = [myMargin.top, myMargin.left, myDoc.documentPreferences.pageHeight - myMargin.bottom, myDoc.documentPreferences.pageWidth - myMargin.right];
              var myOldRuler = myDoc.viewPreferences.rulerOrigin;
              myDoc.viewPreferences.rulerOrigin = RulerOrigin.pageOrigin;
              with(myDoc.pages[-1].textFrames.add()) {
                  geometricBounds = myBounds;
                  if (myDoc.pages[-2].textFrames.length >= 3) {
                      previousTextFrame = myDoc.pages[-2].textFrames[myIndexStart];
                  } else {
                      previousTextFrame = myDoc.pages[-2].textFrames[0];
                  }
                  textFramePreferences.textColumnCount = 2;
                  textFramePreferences.textColumnGutter = 5;
              }
              myDoc.viewPreferences.rulerOrigin = myOldRuler;
          }