Add watermark with file name and page numbers using JavaScript
Hi. I'm trying to write a script for incorporation into a custom Action that can run on a batch of files. The goal is to add a watermark in the upper right-hand corner of all pages with:
- Line 1: File ID = [file name without extension]
- Line 2: Page # of 30
For example, for a pdf named 'MyFile.pdf' that contains 30 pages, the script would add the following text in the upper left corner of each page:
File ID = MyFile
Page # of 30
where # starts at 1 and increments by 1 on each subsequent page
See draft script below. As written, it only adds the watermark to the first page of the pdf. I've successfully created scripts to do each line of the watermark independently, but can't seem to figure out how to accomplish both into a single script. Any suggestions are very appreciated!
for (var p = 0; p < this.pageNum; p++);
var cMyText = "File ID = " + event.target.documentFileName.replace(/\.pdf$/i,"") + "\nPage " + (p+1) + " of " + numPages;
event.target.addWatermarkFromText({
cText: cMyText,
nFontSize:10,
aColor: color.red,
nHorizAlign:app.constants.align.left,
nHorizValue: 36,
nVertAlign:app.constants.align.top,
nVertValue: -36,
nStart: p
});
