- 入力チェック、用紙の向き、回転は考慮しない
- 新規作成されたPDFで細線が発生する場合があります
var strCropBox = "" +
(() => {
const paperWidth = Number(app.response({
cQuestion: "変更後における\r用紙の幅[mm]を半角数字で入力",
cTitle: "paperWidth",
cDefault: "420", bPassword: false,
cLabel: "幅[mm]"
}));
const paperHeight = Number(app.response({
cQuestion: "変更後における\r用紙の高さ[mm]を半角数字で入力",
cTitle: "paperHeight",
cDefault: "297", bPassword: false,
cLabel: "高さ[mm]"
}));
const doc = this;
var pageNum;
var xll, yll, xur, yur;
var marginLeft, marginBottom;
var xllNew, yllNew, xurNew, yurNew;
for (pageNum = 0; pageNum < doc.numPages; pageNum++) {
[xll, yur ,xur ,yll] = doc.getPageBox({
cBox: "Crop", nPage: pageNum
}).map(x => 25.4 / 72 * x);
marginLeft = (paperWidth - (xur - xll)) / 2;
marginBottom = (paperHeight - (yur - yll)) / 2;
xllNew = xll - marginLeft;
yllNew = yll - marginBottom;
xurNew = xllNew + paperWidth;
yurNew = yllNew + paperHeight;
doc.setPageBoxes({
cBox: "Crop", nStart: pageNum, nEnd: pageNum,
rBox: [xllNew, yurNew, xurNew, yllNew].map(
x => 72 / 25.4 * x
)
});
doc.setPageBoxes({
cBox: "Media", nStart: pageNum, nEnd: pageNum,
rBox: [0, yurNew - yllNew, xurNew - xllNew, 0].map(
x => 72 / 25.4 * x
)
});
["Art", "Trim", "Bleed"].forEach(box =>
doc.setPageBoxes({
cBox: box, nStart: pageNum, nEnd: pageNum
})
);
}
}).toString();
var strWatermark = "" +
(() => {
const paperWidth = Number(app.response({
cQuestion: "新規PDFにおける\r用紙の幅[mm]を半角数字で入力",
cTitle: "paperWidth",
cDefault: "297", bPassword: false,
cLabel: "幅[mm]"
}));
const paperHeight = Number(app.response({
cQuestion: "新規PDFにおける\r用紙の高さ[mm]を半角数字で入力",
cTitle: "paperHeight",
cDefault: "210", bPassword: false,
cLabel: "高さ[mm]"
}));
const scale = Number(app.response({
cQuestion: "scale = -1 または 0 < scale",
cTitle: "scale",
cDefault: "0.67", bPassword: false,
cLabel: "scale"
}));
var pageNum;
var xllNew, yllNew, xurNew, yurNew;
const docThis = this;
const docNew = app.newDoc();
for (pageNum = 1; pageNum < docThis.numPages; pageNum++) {
docNew.newPage();
}
for (pageNum = 0; pageNum < docThis.numPages; pageNum++) {
xllNew = 0;
yllNew = 0;
xurNew = paperWidth;
yurNew = paperHeight;
docNew.setPageBoxes({
cBox: "Crop", nStart: pageNum, nEnd: pageNum,
rBox: [xllNew, yurNew, xurNew, yllNew].map(
x => 72 / 25.4 * x
)
});
docNew.setPageBoxes({
cBox: "Media", nStart: pageNum, nEnd: pageNum,
rBox: [0, yurNew - yllNew, xurNew - xllNew, 0].map(
x => 72 / 25.4 * x
)
});
["Art", "Trim", "Bleed"].forEach(box =>
docNew.setPageBoxes({
cBox: box, nStart: pageNum, nEnd: pageNum
})
);
docNew.addWatermarkFromFile({
cDIPath: docThis.path,
nSourcePage: pageNum,
nStart: pageNum, nEnd: pageNum,
bOnTop: true, bOnScreen: true, bOnPrint: true,
nHorizAlign: app.constants.align.center,
nVertAlign: app.constants.align.center,
nHorizValue: 72 / 25.4 * 0,
nVertValue: 72 / 25.4 * 0,
bPercentage: false,
nScale: scale,
bFixedPrint: false, nRotation: 0, nOpacity: 1.0
});
}
}).toString();
var srcCropBox = util.printf("(%s)();", strCropBox);
var srcWatermark = util.printf("(%s)();", strWatermark);
app.addSubMenu({
cName: "myTest",
cUser: "JavaScript練習",
cParent: "Edit", nPos: 0
});
app.addMenuItem({
cName: "myCropBox",
cUser: "全ページでページボックスを変更",
cParent: "myTest", nPos: 0,
cExec: srcCropBox,
cEnable: 'event.rc = (event.target != null);',
cMarked: 'event.rc = false;',
bPrepend: false
});
app.addMenuItem({
cName: "-",
cParent: "myTest", nPos: 1,
cExec: '', bPrepend: false
});
app.addMenuItem({
cName: "myWatermark",
cUser: "PDFを新規作成して全ページを透かしとして入れる",
cParent: "myTest", nPos: 2,
cExec: srcWatermark,
cEnable: 'event.rc = (event.target != null);',
cMarked: 'event.rc = false;',
bPrepend: false
});
app.addMenuItem({
cName: "-",
cParent: "myTest", nPos: 3,
cExec: '', bPrepend: false
});
app.addMenuItem({
cName: "myDebugger",
cUser: "JavaScriptデバッガーのウィンドウを表示",
cParent: "myTest", nPos: 4,
cExec: '\
(() => {\
console.show();\
})();\
',
cEnable: 'event.rc = true;',
cMarked: 'event.rc = false;',
bPrepend: false
});