Highlighted

Add watermark to all files that are opened

New Here ,
Jul 30, 2020

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.

Most Valuable Participant
Correct answer by Test Screen Name | Most Valuable Participant

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".

Topics

How to

Views

60

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Add watermark to all files that are opened

New Here ,
Jul 30, 2020

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.

Most Valuable Participant
Correct answer by Test Screen Name | Most Valuable Participant

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".

Topics

How to

Views

61

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Adobe Community Professional ,
Jul 30, 2020

Copy link to clipboard

Copied

In the console execute

addWatermarkToPdf();

after you have open the PDF file.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
New Here ,
Jul 30, 2020

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.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Adobe Community Professional ,
Jul 30, 2020

Copy link to clipboard

Copied

Remove the last 2 lines from your script.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Most Valuable Participant ,
Jul 30, 2020

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. 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Most Valuable Participant ,
Jul 31, 2020

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.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
New Here ,
Jul 31, 2020

Copy link to clipboard

Copied

So is there anyway to run the javascrpt on a file automatically when it opens? Thanks.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Most Valuable Participant ,
Jul 31, 2020

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".

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
New Here ,
Jul 31, 2020

Copy link to clipboard

Copied

Thanks for the clarification.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Resources
One Stop Solution for Acrobat
Edit a PDF