Copy link to clipboard
Copied
I almost have this working but I can't seem to figure out 2 things.
1. Not a deal breaker because it still kind of works, but when I create the document it is not setting the bleed. The black rectangle still extends to bleed but the its not setting in the document setup/bleed.
2. I can't seem to get the text to center, I get "Error Number: 2 Error String: justification is undefined" and I don't understand why. Any help would be greatly appriciated!
// Create a new document with a width of 6 inches, a height of 9 inches, and a bleed of .125 inches
var doc = app.documents.add({
documentPreferences: {
pageWidth: 6,
pageHeight: 9,
bleedTop: .125,
bleedLeft: .125,
bleedBottom: .125,
bleedRight: .125
}
});
// Create a black rectangle that extends to the full bleed
var rect = doc.rectangles.add({
geometricBounds: [-.125, -.125, 9.125, 6.125]
});
rect.fillColor = "Black";
// Create a text frame with the text
var textFrame = doc.textFrames.add();
textFrame.properties =
{
geometricBounds: [2.96,0.25,4.3,5.75],
contents: "Text Here\nand More Here"
};
// Format text
var textRange = textFrame.characters.everyItem();
textRange.appliedFont = "Helvetica Neue LT Std\t77 Bold Condensed";
textRange.pointSize = 51;
textRange.leading = 55;
textRange.fillColor = "Paper";
textRange.justification = justification.CENTER;
1) can you show a screenshot?
2) why are requesting array / collection of all Characters - I'm not JS guy so not sure what everyItem() returns - but you should rather do:
var textRange = textFrame.texts.item(0);
Or even:
var textRange = TextFrame.parentStory;
Justification isn't property of the Character.
Copy link to clipboard
Copied
1) can you show a screenshot?
2) why are requesting array / collection of all Characters - I'm not JS guy so not sure what everyItem() returns - but you should rather do:
var textRange = textFrame.texts.item(0);
Or even:
var textRange = TextFrame.parentStory;
Justification isn't property of the Character.
Copy link to clipboard
Copied
everyItem here just includes every character in the text frame. There is most likely a better way to do it but for now your observation was correct. Center is not a property of character, I got it working correctly by adding this:
thanks again!
textFrame.parentStory.justification = Justification.CENTER_ALIGN;
Copy link to clipboard
Copied
You are welcome 🙂
But it's still not the right way to interact with text objects in the InDesign.
If you have more than one character to process - you should get a reference to the .texts(0) - not to the array/collection of all individual characters - unless, of course, your goal is to process each character individually.
Properties of the Character object are a subset of the properties of the Text object - and Text object is much more universal so if you first get a reference to the Text object - you'll avoid similar errors in the future.
Copy link to clipboard
Copied
Hi @davidn5918184 , not sure if this helps, but the .characters object is a collection not an array— while .characters.everyItem().getElements would return an array:
$.writeln(app.documents[0].stories.everyItem().texts)
//returns [object Texts] a collection (not an array) of text objects
$.writeln(app.documents[0].stories.everyItem().texts.everyItem().getElements())
//returns [object Text],[object Text],[object Text]... an array of text objects
This would set all of the document’s text’s point size and leading to 15/20:
//sets the point size and leading of all the document’s text‘s
app.documents[0].stories.everyItem().texts.everyItem().properties = {pointSize:15, leading:20};
Copy link to clipboard
Copied
To answer your first question, you're calling incorrect properties for the bleed settings. Should be:
documentPreferences: {
pageWidth: 6,
pageHeight: 9,
documentBleedTopOffset: .125,
documentBleedInsideOrLeftOffset: .125,
documentBleedBottomOffset: .125,
documentBleedOutsideOrRightOffset: .125
}
Or more simply:
documentBleedTopOffset: .125,
documentBleedUniformSize: true
See: https://www.indesignjs.de/extendscriptAPI/indesign-latest/#DocumentPreference.html