Copy link to clipboard
Copied
Is there a script that would make a list of the first word of each page (or, preferably, create a text box on each page and place the next page's word in that)? My document's all in one story with one text frame on each page, although there are several other frames (header, page number) applied through master pages.
Copy link to clipboard
Copied
Something like this, maybe...
if( !(app.selection[0] instanceof InsertionPoint) ) {alert("First, target a story by inserting a blinking cursor."); exit(); }
var stry = app.selection[0].parentStory, d = app.documents[0], i, tf1, tf2, wrd, ntf, bnds, pg, ro = d.viewPreferences.rulerOrigin;
d.viewPreferences.rulerOrigin = RulerOrigin.SPREAD_ORIGIN;
for ( i = stry.textContainers.length - 1; i > 0; i-- ) {
tf2 = stry.textContainers;
wrd = tf2.words[0];
tf1 = stry.textContainers[i-1];
pg = tf1.parentPage;
bnds = pg.bounds;
ntf = pg.textFrames.add( undefined, undefined, undefined, {geometricBounds:[ bnds[0], bnds[1], bnds[0] + "3p0", bnds[3] ] } );
ntf.textFramePreferences.verticalJustification = VerticalJustification.BOTTOM_ALIGN;
wrd.duplicate( LocationOptions.AT_BEGINNING, ntf );
ntf.texts[0].justification = Justification.CENTER_ALIGN;
}
d.viewPreferences.rulerOrigin = RulerOrigin[ro];
Copy link to clipboard
Copied
Thanks - it worked great. One follow-up, though - how would I change the position of the new text frames, and make them all linked?
Copy link to clipboard
Copied
geometricBounds controls the size and location of the textframes. Where do you the text to appear?
Copy link to clipboard
Copied
The text box is positioned at X: 10.0681 in, Y: 8.0425 in, and the size is W: 0.8638 in, H 0.085 in. Can it also assign a style?
Copy link to clipboard
Copied
Landscape layout?
Assumes existence of paragraph style called "firstword" in main paragraph styles palette, not inside a paragraph style group.
if( !(app.selection[0] instanceof InsertionPoint) ) {alert("First, target a story by inserting a blinking cursor."); exit(); }
var stry = app.selection[0].parentStory, d = app.documents[0], i, tf1, tf2, wrd, ntf, otf, pg, ro = d.viewPreferences.rulerOrigin;
d.viewPreferences.rulerOrigin = RulerOrigin.PAGE_ORIGIN;
for ( i = stry.textContainers.length - 1; i > 0; i-- ) {
tf2 = stry.textContainers;
wrd = tf2.words[0];
tf1 = stry.textContainers[i-1];
pg = tf1.parentPage;
ntf = pg.textFrames.add( undefined, undefined, undefined, {geometricBounds:[ "8.0425in", "10.0681in", "8.1275in", "10.9319in"]} );
ntf.textFramePreferences.verticalJustification = VerticalJustification.BOTTOM_ALIGN;
wrd.duplicate( LocationOptions.AT_BEGINNING, ntf );
ntf.texts[0].applyParagraphStyle( d.paragraphStyles.itemByName("firstword"), true );
ntf.texts[0].insertionPoints[-1].contents = SpecialCharacters.FRAME_BREAK;
if ( i < stry.textContainers.length - 1 ) ntf.nextTextFrame = otf;
otf = ntf;
}
d.viewPreferences.rulerOrigin = RulerOrigin[ro];
Copy link to clipboard
Copied
Something wasn't working with the styling - it kept freezing the program - so I removed the last four lines and kept the center_align line from the first version. That ran, but the boxes are in the wrong position.
Once you mentioned landscape layout, I realised why the numbers seemed odd - I have 'facing pages' turned on and had checked the position only on the right page. I changed the numbers to "8.0425in", "4.5681in", "8.1275in", "5.4319in" and it mostly worked - it placed the box at exactly 5 inches (X) and at 8.085 inches (Y) instead of 4.5681 inches. Any idea why?
Copy link to clipboard
Copied
Did you create a paragraph style called "firstword" in the document?
What are the dimensions and orientation of your pages?
Copy link to clipboard
Copied
I created the paragraph style.
The pages are portrait orientation, 5.5 x 8.5 inches. I also unchecked 'facing pages' before running the script last time.
Copy link to clipboard
Copied
You wrote: I changed the numbers to "8.0425in", "4.5681in", "8.1275in", "5.4319in" and it mostly worked - it placed the box at exactly 5 inches (X) and at 8.085 inches (Y) instead of 4.5681 inches. Any idea why?
No. I cannot reproduce the error you describe. I assume you've checked your numbers very closely in the script--I don't normally indicate measurements as strings.
you wrote: Something wasn't working with the styling - it kept freezing the program -
What do you mean by "freezing the program"? Is there a specific error message?
The paragraph style is named "firstword" and is all lowercase letters?
firstword paragraph style is NOT in a paragraph style group, right?
Is the first word on any page too long when formatted with the paragraph style "firstword" to fit in the text frame?
Copy link to clipboard
Copied
I figured out what the problem was - I had the coordinates for the middle of the text box, rather than the upper left. I fixed that and it worked. It also wasn't freezing, just taking a really long time - I let it run for about an hour and it finally finished (it's about 700 pages).
Thanks for the script! Even with trying to get it to work, it's much faster than having to type in all the words manually.
Copy link to clipboard
Copied
Hi Paul,
Did you consider using text variable (Match_Character_Style_Type) for catching first and last occurrence of some character style on a page?
This solution could keep dynamic connection to your content (works if text reflows)
Text variables could be added by master pages with proper size, geoBounds and style in a separated text box with its name, say, "bookmark".
Finally, if you would need first word from the next page placed on current page you could use a script. All it have to do is to place
myDoc.pages
in chosen place on page[k-1].
That's only a hint from my side...
Copy link to clipboard
Copied
I'm reading this post and would like to do the same thing (that is, have the first word of the next page at the bottom of the current page). The script on this page appears to do that, but I honestly don't know what to do with the script. 1. Is there an easier way to do this in InDesign 20.0.1? 2. Can someone provide more specific directions of what to do with the script and then how to reference it in a box on the current page? Thanks.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now