Search code examples
adobe-indesign

How to align text vertically in InDesign?


I want a script which would just paste text from current clipboard and align it in the text frame. But I only figured out how to paste, and align it horizontally. How to do it vertically? So the text fits right in the center of the text frame. Here what I have done so far:

app.paste();
app.selection[0].parentStory.justification = Justification.CENTER_ALIGN;

Solution

  • Vertical justification is a text frame property so you'll need to find the frames corresponding to the story. Here's a snippet that picks up where yours ends.

    // Get the parent story of the current selection 
    var myParentStory = app.selection[0].parentStory;
     
    // Get all text frames for that parent story 
    var textFrames = myParentStory.textContainers; 
    
    // Loop through each text frame to set vertical alignment 
    for (var i = 0; i < textFrames.length; i++) {
     textFrames[i].textFramePreferences.verticalJustification = VerticalJustification.CENTER_ALIGN; 
    }