// 获取当前文档的总页数
var totalPages = this.numPages;
// 获取当前文档的名称
var docName = decodeURI(this.documentFileName);
// 获取当前文档的全路径
var docPath = decodeURI(this.path);
// 获取当前文档的父路径
var docParentPath = decodeURI(this.path.replace(/[^/\\]*$/, ""));
var pt = 72/25.4;
// 遍历每一页
for (var i = 0; i < totalPages; i++) {
// 获取当前页面的尺寸 如果页面有旋转,尺寸不一定正确
var pageWidth = this.getPageBox("Media", i)[2]/pt;
var pageHeight = this.getPageBox("Media", i)[1]/pt;
// 设置水印文本内容(1.450001).toFixed(1)
var text =docPath+"《"+ pageWidth.toFixed(1)+'x'+pageHeight.toFixed(1)+"》"+"["+ (i + 1) + "-" + totalPages + "]";
// 添加水印到当前页面
this.addWatermarkFromText({
cText: text,
nTextAlign: app.constants.align.left,
nHorizAlign: app.constants.align.left,
nVertAlign: app.constants.align.bottom,
nHorizValue: 0,
nVertValue: 0,
aColor: ["CMYK", 0, 0, 0, 1],
//aColor: color.black,
cFont: "MicrosoftYaHei",
nFontSize: 5,
nStart: i,
nEnd: i,
bOnTop: false
});
}