: SpecialCharacters.PAGE_BREAK compare against TextFrame.contents var myStories = app.activeDocument.stories.everyItem().getElements(); for (i = myStories.length - 1; i >= 0; i--){ var myTextFrames
var myStories = app.activeDocument.stories.everyItem().getElements();
for (i = myStories.length - 1; i >= 0; i--){
var myTextFrames = myStories[i].textContainers;
$.writeln(myTextFrames.length);
for (j = myTextFrames.length - 1; j >= 0; j--) {
$.writeln(myTextFrames[j].contents);
if (myTextFrames[j].contents == SpecialCharacters.PAGE_BREAK){
$.writeln("test hier");
myTextFrames[j].remove();
}
}
}
why does this not work? I guess because the SpecialCharacters.PAGE_BREAK is a number but I cannot make it work, I tried so much.
The condition gets never true even if there only a pagebreak in the textframe.
More posts by @Connie430
2 Comments
Sorted by latest first Latest Oldest Best
I think I get what you are looking for but mdomino is right. You did not ask any question. To check if your textframe or story has a SpecialCharacters.PAGE_BREAK character you cant compare the whole contents of a textFrame. You need to examine each character on its own. This code should get do what you want.
var doc = app.activeDocument;
var story = doc.stories[0];
for(var i = 0; i < story.characters.length; i++) {
if(story.characters.item(i).contents === SpecialCharacters.PAGE_BREAK) {
$.writeln('found the page break SpecialCharacters.PAGE_BREAK at index ' + i);
}
}
Reading the contents property seems to only return string objects. I am not sure why exactly that is the case, but the SpecialCharacters can be used for writing only in a script context (somebody correct me, if I am wrong, please). So the most simple way to check for a single page break in a text frame would be to simply check for a break in that frame:
if(myTextFrames[j].contents === "r")
Note that this will also return true for column breaks, frame breaks etc. If you need to find page breaks only, I think you need to script a GREP search for page breaks, which would be a bit more involved.
Btw. it would be nice, if you could ask your question with an actual explanation of your problem and what the code is supposed to do, instead of only pasting some code and asking, why it does not work. People are much more likely to help you, if you help them understand your problem quickly.
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2025 All Rights reserved.