• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Add watermark to all files that are opened

New Here ,
Jul 30, 2020 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.

TOPICS
How to

Views

612

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
community guidelines

correct answers 1 Correct answer

LEGEND , Jul 31, 2020 Jul 31, 2020

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

Votes

Translate

Translate
Community Expert ,
Jul 30, 2020 Jul 30, 2020

Copy link to clipboard

Copied

In the console execute

addWatermarkToPdf();

after you have open the PDF file.

Votes

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
community guidelines
New Here ,
Jul 30, 2020 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.

Votes

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
community guidelines
Community Expert ,
Jul 30, 2020 Jul 30, 2020

Copy link to clipboard

Copied

Remove the last 2 lines from your script.

Votes

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
community guidelines
LEGEND ,
Jul 30, 2020 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. 

Votes

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
community guidelines
Community Expert ,
Jul 31, 2020 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.

Votes

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
community guidelines
New Here ,
Jul 31, 2020 Jul 31, 2020

Copy link to clipboard

Copied

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

Votes

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
community guidelines
LEGEND ,
Jul 31, 2020 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".

Votes

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
community guidelines
New Here ,
Jul 31, 2020 Jul 31, 2020

Copy link to clipboard

Copied

LATEST

Thanks for the clarification.

Votes

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
community guidelines