ParagraphStyles
ParagraphStyles
Section titled “ParagraphStyles”app.activeDocument.paragraphStyles
Description
Section titled “Description”A collection of ParagraphStyle objects.
Properties
Section titled “Properties”ParagraphStyles.length
Section titled “ParagraphStyles.length”app.activeDocument.paragraphStyles.length
Description
Section titled “Description”Number of elements in the collection.
Number; read-only.
ParagraphStyles.parent
Section titled “ParagraphStyles.parent”app.activeDocument.paragraphStyles.parent
Description
Section titled “Description”The object’s container.
Object; read-only.
ParagraphStyles.typename
Section titled “ParagraphStyles.typename”app.activeDocument.paragraphStyles.typename
Description
Section titled “Description”The class name of the object.
String; read-only.
Methods
Section titled “Methods”ParagraphStyles.add()
Section titled “ParagraphStyles.add()”app.activeDocument.paragraphStyles.add(name)
Description
Section titled “Description”Creates a named paragraph style.
Parameters
Section titled “Parameters”Parameter | Type | Description |
---|---|---|
name | String | Name of element to get |
Returns
Section titled “Returns”ParagraphStyles.getByName()
Section titled “ParagraphStyles.getByName()”app.activeDocument.paragraphStyles.getByName(name)
Description
Section titled “Description”Get the first element in the collection with the provided name.
Parameters
Section titled “Parameters”Parameter | Type | Description |
---|---|---|
name | String | Name of element to get |
Returns
Section titled “Returns”ParagraphStyles.index()
Section titled “ParagraphStyles.index()”app.activeDocument.paragraphStyles.index(itemKey)
Description
Section titled “Description”Gets an element from the collection.
Parameters
Section titled “Parameters”Parameter | Type | Description |
---|---|---|
itemKey | String, Number | String or number key |
Returns
Section titled “Returns”ParagraphStyles.removeAll()
Section titled “ParagraphStyles.removeAll()”app.activeDocument.paragraphStyles.removeAll()
Description
Section titled “Description”Deletes all elements in the collection.
Returns
Section titled “Returns”Nothing.
Example
Section titled “Example”Creating and applying a paragraph style
Section titled “Creating and applying a paragraph style”// Creates a new document with 1 text frame and 3 paragraphs// gives each paragraph a different justification, then creates// a paragraph style and applies it to all paragraphs
var docRef = documents.add();var pathRef = docRef.pathItems.rectangle(600, 200, 200, 400);var textRef = docRef.textFrames.areaText(pathRef);textRef.paragraphs.add("Left justified paragraph.");textRef.paragraphs.add("Center justified paragraph.");textRef.paragraphs.add("Right justified paragraph.");textRef.textRange.characterAttributes.size = 28;
// change the justification of each paragraph// using the paragraph attributes objectvar paraAttr_0 = textRef.paragraphs[0].paragraphAttributes;paraAttr_0.justification = Justification.RIGHT;
var paraAttr_1 = textRef.paragraphs[1].paragraphAttributes;paraAttr_1.justification = Justification.CENTER;
var paraAttr_2 = textRef.paragraphs[2].paragraphAttributes;paraAttr_2.justification = Justification.LEFT;
// create a new paragraph stylevar paraStyle = docRef.paragraphStyles.add("LeftIndent");
// add some paragraph attributesvar paraAttr = paraStyle.paragraphAttributes;paraAttr.justification = Justification.LEFT;paraAttr.firstLineIndent = 10;
// apply the style to each item in the documentvar iCount = textRef.paragraphs.length;for (var i = 0; i < iCount; i++) { paraStyle.applyTo(textRef.paragraphs[i], true);}redraw();