Copy link to clipboard
Copied
I have added a javascript file to the C:\Program Files (x86)\Adobe\Acrobat DC\Acrobat\Javascripts directory that I wanted to run each time a file is opened. The script is as follows:
var addWatermarkToPdf = app.trustedFunction(function(){
app.beginPriv();
this.addWatermarkFromFile({
cDIPath: "/E/Printing Support/Images/Watermark.jpg",
nHorizAlign: app.constants.align.bottom,
nVertAlign: app.constants.align.bottom,
nHorizValue: 175.0, nVertValue: 25.0,
nRotation: 0,
nScale: .80
});
app.endPriv() ;
});
app.alert("here 1",3);
addWatermarkToPdf();
I can't seem to get the addWatermarkToPdf() function to run when called by this javascript file. The debugger is indicating that 'this' is not defined. Is this possible to do what I want? Any help would be appreciated.
You can embed it INSIDE the file, to apply to THAT file.
Acrobat has nothing to allow JavaScript to "wait for a file to open then pounce".
Copy link to clipboard
Copied
In the console execute
addWatermarkToPdf();
after you have open the PDF file.
Copy link to clipboard
Copied
After I open the file the console has this error message: TypeError: this.addWatermarkToPdf is not a function
10:Folder-Level:App:Test.js. I am new to this so I am not sure how to run the function from the debugger. Thanks.
Copy link to clipboard
Copied
Remove the last 2 lines from your script.
Copy link to clipboard
Copied
Don't try to run the function from the JavaScripts folder. This only used to define the function. You can't call it because at that moment no files are open yet.
Copy link to clipboard
Copied
In addition to what already said, I would recommend passing a reference to the Document object as a parameter, instead of using the "this" keyword in your trusted function.
Copy link to clipboard
Copied
So is there anyway to run the javascrpt on a file automatically when it opens? Thanks.
Copy link to clipboard
Copied
You can embed it INSIDE the file, to apply to THAT file.
Acrobat has nothing to allow JavaScript to "wait for a file to open then pounce".
Copy link to clipboard
Copied
Thanks for the clarification.