-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathpdfPlacer_singlepage.jsx
74 lines (65 loc) · 1.67 KB
/
pdfPlacer_singlepage.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
var w = app.dialogs.add();
w.name = "Parameters";
w.canCancel = true;
var tg = w.dialogColumns.add();
var xg = tg.dialogRows.add();
xg.staticTexts.add({staticLabel:"x1:"});
var x = xg.textEditboxes.add();
x.editContents = "0";
var yg = tg.dialogRows.add();
yg.staticTexts.add({staticLabel:"y1:"});
var y = yg.textEditboxes.add();
y.editContents = "0";
var wdg = tg.dialogRows.add();
wdg.staticTexts.add({staticLabel:"x2:"});
var wd = wdg.textEditboxes.add();
wd.editContents = "210";
var hg = tg.dialogRows.add();
hg.staticTexts.add({staticLabel:"y2:"});
var h = hg.textEditboxes.add();
h.editContents = "297";
var lst = ["cropMedia","cropTrim","cropArt","cropBleed","cropPdf"];
var dd = tg.dropdowns.add();
dd.stringList = lst
dd.selectedIndex = 0;
if(w.show()){
var bds = [
Number(y.editContents),
Number(x.editContents),
Number(h.editContents),
Number(wd.editContents)];
var crop = lst[dd.selectedIndex];
w.destroy();
main(bds,crop);
}
else {
w.destroy();
}
function main(bds,crop){
var tgt = app.activeDocument;
fNm = File.openDialog("select PDF file");
var f = new File (fNm);
var pgLen = pg;
var num = 1;
var pNum = 1;
var flg = false;
var i = 0;
var pg = tgt.pages[i];
eval("app.pdfPlacePreferences.pdfCrop = PDFCrop."+crop);
while(!flg){
app.pdfPlacePreferences.pageNumber = pNum++;
rect = pg.rectangles.add();
rect.strokeColor = tgt.swatches.item(0);
rect.fillColor = tgt.swatches.item(0);
rect.place(f);
rect.geometricBounds = bds;
rect.fit(FitOptions.PROPORTIONALLY);
rect.fit(FitOptions.CENTER_CONTENT);
if(i>1&&rect.graphics[0].itemLink.parent.pdfAttributes.pageNumber == num) {
pg.remove();
break;
}
i++;
pg = tgt.pages.add();
}
}