-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexportSpecificPagePDF.jsx
104 lines (96 loc) · 3.73 KB
/
exportSpecificPagePDF.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
102
103
104
/**
* @fileoverview ページパネルで選択したページのみをPDFとして書き出す(PDF書き出しダイアログを開く)スクリプト
* @author Yusuke SAEGUSA(Uske_S)
* @version 0.0.2 とりあえず版
*/
//@target "indesign"
app.doScript(function() {
//-- 変数定義 --//
var doc, pag, exPageColors, tgtPages, tgtFolder, fileName;
/**
* スクリプト動作前後では表示されないため特に意識する必要はないが,ページパネルの色名とオブジェクトを対応させている
*
* @property {string} jp ページパネルのカラー設定のメニュー名(和文表記)
* @property {stirng} en 上記jpに対応するpageColorオブジェクトのキーストリング
*/
var clr = {jp: "黒", en: "BLACK"};
var act = app.menuActions.itemByName(clr.jp); //ページパネルのカラー設定メニュー
//-- 関数定義 --//
/**
* 指定した色が設定されたページの絶対ページ番号をカンマ区切りにして返す
*
* @param {string} colorName pageColorのキー名
* @return {string} カンマ区切りテキスト
*/
function getColoredPages(colorName) {
var res = [];
for (var i=0; i<pag.length; i++) {
if (pag[i].pageColor.toString() === colorName) {
res.push("+"+(i+1));
}
}
return res.join(",");
};
/**
* 現在のページのカラー設定をプールして削除する
*
* @return {string[]} pageColorのキーの配列
*/
function clearPageColor() {
var res = [];
for (var i=0; i<pag.length; i++) {
res.push(pag[i].pageColor.toString());
pag[i].pageColor = PageColorOptions.NOTHING;
}
return res;
};
/**
* ページのカラー設定を復元する
*
* @param {string[]} pgColorValue pageColorのキーが入った配列
*/
function returnPageColor(pgColorValue) {
for (var i=0; i<pag.length; i++) {
if (pgColorValue[i] === "NOTHING" || pgColorValue[i] === "USE_MASTER_COLOR") {
pag[i].pageColor = PageColorOptions[pgColorValue[i]];
} else {
pag[i].pageColor = UIColors[pgColorValue[i]];
}
}
};
/**
* PDF書き出しダイアログを開く
*
* @param {string} range PDF書き出し範囲
* @param {file} filePath 書き出し先のファイルオブジェクト
*/
function openExportDialog(range, filePath) {
app.pdfExportPreferences.pageRange = range;
doc.exportFile(ExportFormat.PDF_TYPE, filePath, true);
};
//-- 実行処理 --//
if (app.documents.length === 0) {exit();}
doc = app.activeDocument
pag = doc.pages;
exPageColors = clearPageColor();
if (!act.hasOwnProperty("length") && act.area === "パネルメニュー:ページ" && act.enabled) {
act.invoke();
} else {
alert("ページパネルからアクションを実行できませんでした。スクリプトを中断します");
returnPageColor(exPageColors);
exit();
}
tgtPages = getColoredPages(clr.en);
tgtFolder = Folder.selectDialog("PDF書き出し先のフォルダを選択");
if (!tgtFolder) {
returnPageColor(exPageColors);
exit();
}
fileName = prompt("PDFのファイル名を入力(拡張子まで含めて入力)", decodeURI(doc.name).replace(/\.indd$/, ".pdf"));
if (!fileName) {
returnPageColor(exPageColors);
exit();
}
openExportDialog(tgtPages, new File(tgtFolder.fsName+"/"+fileName));
returnPageColor(exPageColors);
}, ScriptLanguage.JAVASCRIPT, null, UndoModes.ENTIRE_SCRIPT);