Adding Watermark in Adobe JavaScript
Hello all,
my task is to add a Watermark based on key words in the pdf file on the first page. So if there is "DEST. 117.00 USD" in pdf file then add as a watermark "45125-123" if there is in file "Credit note" then add watermark "457-125" if nothing from above then add nothing. I checked it cannot be the situation when both variants "DEST. 117.00 USD" and "Credit note" can be in the file.
So, please help me to write a code in adobe JavaScript to solve this issue.
Please keep in mind that I am new to coding. I tried to write a part of the code.
Thanks for any support.
var pageArray = [];
var stringToSearchFor = "page\s1\sof\s1";
for (var p = 0; p < this.numPages; p++) {
// iterate over all words
for (var n = 0; n < this.getPageNumWords(p); n++) {
if (this.getPageNthWord(p, n) == "DEST. 117.00 USD") {
pageArray.push(p);
break;
}}
}
if (pageArray.length > 0) {
this.addWatermarkFromText({
cText: util.printd("45125-123", new Date()),
nHorizAlign: app.constants.align.center,
nVertAlign: app.constants.align.bottom,
nVertValue: 16, nFontSize: 10
});
}
else if (pageArray.length = 0) {
this.addWatermarkFromText({
cText: util.printd("457-125", new Date()),
nHorizAlign: app.constants.align.center,
nVertAlign: app.constants.align.bottom,
nVertValue: 15, nFontSize: 9
});}
else {}