-
Notifications
You must be signed in to change notification settings - Fork 7
/
_buildDocument.jsx
101 lines (82 loc) · 2.55 KB
/
_buildDocument.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
// basic javascript snippets for indesign cs 4
// written by fabiantheblind
// this builds a basic doc with a page. A paragraphstyle a characterstyle
// and some lorem ipsum text in a textframe with 3 columns in the bounds
main();
function main (){
var theDoc = buildDoc();
theStyles(theDoc);
var thePage = theDoc.pages.item(0);
var theTextFrame = thePage.textFrames.add({
geometricBounds:getBounds(theDoc,thePage)
});
theTextFrame.textFramePreferences.textColumnCount = thePage.marginPreferences.columnCount;
theTextFrame.textFramePreferences.textColumnGutter = thePage.marginPreferences.columnGutter;
theTextFrame.contents = TextFrameContents.placeholderText;
}
function theStyles(theDoc){
parStyle = theDoc.paragraphStyles.add({name:"parStyle"});
with(parStyle){
leading = 23;
pointSize = 13;
}
charStyle = theDoc.characterStyles.add({name:"charStyle"});
with(charStyle){
leading = 23;
pointSize = 13;
}
}
function buildDoc(){
var theDoc = app.documents.add()
with (theDoc.documentPreferences) {
pageWidth = "210mm";
pageHeight = "210mm";
//BleedBox settings
documentBleedBottomOffset = "3mm";
documentBleedTopOffset = "3mm";
documentBleedInsideOrLeftOffset = "3mm";
documentBleedOutsideOrRightOffset = "3mm";
}
// have to look up why the size is declared in 2 ways
with (theDoc.viewPreferences) {
pageWidth = "210mm";
pageHeight = "210mm";
// to make shure we have the right positions and units
horizontalMeasurementUnits = MeasurementUnits.MILLIMETERS;
verticalMeasurementUnits = MeasurementUnits.MILLIMETERS;
rulerOrigin = RulerOrigin.pageOrigin;
}
with(theDoc.masterSpreads.item(0).pages.item(0).marginPreferences){
left = "13mm";
top = "23mm";
right = "13mm";
bottom = "23mm";
columnCount = 3;
columnGutter = "4mm";
}
with(theDoc.masterSpreads.item(0).pages.item(1).marginPreferences){
left = "13mm";
top = "23mm";
right = "13mm";
bottom = "23mm";
columnCount = 3;
columnGutter = "4mm";
}
return theDoc;
}
function getBounds(myDocument, myPage){
var myPageWidth = myDocument.documentPreferences.pageWidth;
var myPageHeight = myDocument.documentPreferences.pageHeight
if(myPage.side == PageSideOptions.leftHand){
var myX2 = myPage.marginPreferences.left;
var myX1 = myPage.marginPreferences.right;
}
else{
var myX1 = myPage.marginPreferences.left;
var myX2 = myPage.marginPreferences.right;
}
var myY1 = myPage.marginPreferences.top;
var myX2 = myPageWidth - myX2;
var myY2 = myPageHeight - myPage.marginPreferences.bottom;
return [myY1, myX1, myY2, myX2];
}