5 Replies Latest reply on Jan 16, 2015 2:57 AM by Bernd Alheit

    I keep receiving security errors when trying to open a pdf.

    benf2015

      I keep receiving a security error when trying to run my javascript program, the function previously worked, but now creates an error after I entered the addWaterMark function. I have put my whole code below for my script.

       

      The basic function is to load a text file into an array which has the path and file location, open the document, add a watermark, save the file, close the file, then repeat for the next array position.

       

      I am using Acrobat Standard so I am unable to debug using the console, therefore I am struggling to understand what I am doing wrong. I will point out that I am not a fluent programmer, only have a basic knowledge of programming.

       

      Code

       

      app.addSubMenu(

        {

        cName:"Extras",

        cParent:"Edit"

        }

      )

       

       

       

       

      app.addMenuItem(

        {

        cName:"Import File",

        cParent:"Extras",

        cExec:"main()"

        }

      )

       

       

      function main()

        {

        var fileCount = 0

        var listOfFiles = []

        listOfFiles = importData()

       

        amountOfFiles = listOfFiles.length

       

       

        for (var i =0; i<listOfFiles.length; i++)   //calculates amount of entries in the array listOfFiles

       

       

        {

        newFile = openFile(listOfFiles[i]) //Opens current file

        var d = app.activeDocs; //Gets current document title name 

        addWater(d[0]);

        app.execMenuItem("Save");

        for( var x in d ) d[x].closeDoc();

        }

        }

       

       

       

       

      function addWater(myName)

      { app.alert("watermark",0);

        myName.addWatermarkFromText(

        {

        cText: "OBSOLETE",

        cFont: "Arial",

        nFontSize:36,

        aColor: color.red,

        nOpacity: 0.5

        }

        );

      }

       

       

       

       

      //function SaveFile saves the current file but with an addition of WM to the filename

      saveFile = app.trustedFunction(function(currentDoc, currentFileName)

        { app.alert("savefile",0);

        app.beginPriv();

        currentDoc.saveAs(currentFileName);

        app.endPriv();

        }

      );

       

       

       

       

      //function openFile which opens the file named in the variable currentFilename

      openFile = app.trustedFunction(function(currentFileName)

        {app.alert("openfile" + currentFileName,0);

        app.beginPriv();

        app.openDoc(currentFileName);

        app.endPriv();

        }

      );

       

       

       

       

      //importData function imports the paths and filenames contained in the list.txt located on the desktop

      importData = app.trustedFunction(function()

        {app.alert("import",0);

        app.beginPriv();

        cFilePath = "/C/Users/103019944/Desktop/File_List.txt";

        var stmData = util.readFileIntoStream(cFilePath);

        var cData = util.stringFromStream(stmData);

        var cMsg = cData;

        var fileArray = cMsg.split("\r\n");

        for (var i =0; i<fileArray.length; i++)

        return(fileArray);

        app.endPriv();

        }

      );