4 Replies Latest reply on Mar 18, 2014 1:39 AM by alex@byom

    How do I enter a page break? (CS5)


      I have a routine which reads an XML file and builds an ID document. How do I create a page break by adding to the current insertionPoint? I tried it with

        story.insertionPoints.lastItem().contents += SpecialCharacters.pageBreak;

      but those special characters seem to apply only to XML. What is the alternative? - I'm using ID CS5.

        • 1. Re: How do I enter a page break? (CS5)
          Laubender Adobe Community Professional & MVP

          @Alex – you can add a pageBreak special character at the end of a story like that:


          //Adding a pageBreak at the end of a story:
          var myStory = app.documents[0].stories[0];
          myStory.insertionPoints.lastItem().contents = SpecialCharacters.pageBreak;


          Just tested that in InDesign CS5.5.



          • 2. Re: How do I enter a page break? (CS5)
            alex@byom Level 1

            Thank you, you're right. What I do not understand, though, is the difference between "=" and "+=" at this point. With the concatenation operator ID does not create a page break but inserts the code for it instead in the text.

            • 3. Re: How do I enter a page break? (CS5)
              [Jongware] Most Valuable Participant

              It's not InDesign that does it, but rather Javascript's syntax. Oh ... and a bit of yours as well.


              A 'contents' item may be a SpecialCharacters enumeration -- a number --, or a text string. The way you refer to the existing item, you might get either: if that last character happens to be representable as one of the Special Characters, you get a number; if not, you get a string.


              So what happens, using the '+' operator and a number on something of which you are not sure what type it is?


              1. If you get a string back, you are in trouble, because Javascript forbids adding Number to String. If the string cannot be coerced into a number (and usually it can't), then the number is coerced into a string. The string form of a number is the set of its digits, and therefore, logically, adding "SpecialCharacters.pageBreak" to a random string adds the characters "1397778242".


              2. If you get a number back, you are in even more trouble! Suppose there already happened to be a "Special Character" enumerated value on that last position -- say, an en-dash ("SpecialCharacters.EN_DASH"). Its numerical representation -- which gets returned if you query it -- is 1397059140. Guess what happens if you use '+=' to ADD the number 1397778242 (your page break, remember) to it? You get the value 2794837382, which, uh, will appear as such. ID does not realize it "is" the value of an en dash added to the value of a page break; it's just a number.


              What's the difference when you use text strings? Usually, the following construction will work:


              story.insertionPoints.lastItem().contents += 'hello happy world!';


              .. but not always! It will fail when the contents of that last insertionPoint is .. one of the SpecialCharacters values. And at that point, you get the same as above (only the other way around).


              It works when you use a direct assignment "=" because you can assign either a string value or a SpecialCharacter enumeration to a single character.

              • 4. Re: How do I enter a page break? (CS5)
                alex@byom Level 1

                Thanks a lot. I think I've got it. Until next time, at least.