5 Replies Latest reply on Nov 9, 2011 7:40 AM by try67



      I have a file in C:\Program Files\Adobe\Acrobat 9.0\Acrobat\Javascripts called letterhead.js


      Contents of letterhead.js


        function letterhead () {










      When I open acrobat, press control + j to launch the console, and type in:




      I get the following error


      Exception in line 3 of function letterhead, script Folder-Level:App:letterhead.js, with an arrow next to the addWatermarkFromFile line.


      Can anyone point me in a direction to solve this? Ultimately, the goal is to have a script that applies a background using this file as the source to the currently selected page, and then flatten the document.

        • 1. Re: addWatermarkFromFile
          BarlaeDC Adobe Community Professional



          The problem is that you are using the 'this' object. Where you code is placed the 'this' object is not a document object which it needs to be in order to be able to call the function you would like.


          To have this code function as you would like, the code would need to be change to something like


          function letterhead ( myDocObj) {






               app.trustedFunction ( letterhead);


          then when you are trying to call it you would pass the document object that you wish to be used.


          Possible using the app.activeDocs function.


          // note this is best tested with only 1 document open as it uses the first document in the list, not what I would do for a long term solution, but should do for checking that your code works.

          letterhead ( app.activeDocs[0]);


          Hope this helps.



          • 2. Re: addWatermarkFromFile
            gkaiseril MVP & Adobe Community Professional

            The root directory of the c: drive is not a safe path. You should place the logo PDF in subdirectory of the root directory. See the Acrobat JS API Reference for more information.

            • 3. Re: addWatermarkFromFile
              djakay Level 1

              Thank you, I will try this right away. Makes sense that 'this' would refer to the function I assume, and not the doc calling the function.


              ~GKaiser, thanks for the heads up. I am only using root of C for testing purposes, unless root of C is treated differently in adoba javascript. It will be changed to a network path most probably but if I get this base case to work than I will tackle network security restrictions when that comes (though I have a feeling as long as the windows user has permission to read the network folder it would work)


              ~2nd Edit


              Marked as correct, changing the 'this' to the passed variable and passing in what document to apply the watermark to worked. Thank you.

              • 4. Re: addWatermarkFromFile
                BarlaeDC Adobe Community Professional

                Although I agree that the root of 'c' is not a safe path ( and I would move the file as per the above instructions), this should not cause any issues for this code as we are not writing to the c drive.

                • 5. Re: addWatermarkFromFile
                  try67 MVP & Adobe Community Professional

                  Correct. In this case the file doesn't need to be in a safe path.