TrustedFunction

Hi,
I'm trying to add an app.launchURL to each Bookmark in the setAction bookmark method.
app.launchURL needs security privileges, then I have created a trustedFunction for that.
I'm using a bucle to assign the URL with differents varibles values for each Bookmark.
The Code in the web:
var bkm = this.bookmarkRoot;
var p = "";
for( k=0; k < bkm.children.length; k++){
    p = "http://localhost/directory/tPDF.php?p="+k;
        app.alert({
         cMsg: "bookmark: "+bkm.children[k].name+" trustedlURL("+p+")",
         cTitle: "Testing"
        bkm.children[k].setAction("trustedlURL(p);");
}//end for
This is the function at the app folder-level Javascript file.
trustedlURL = app.trustedFunction( function (value)
        // Additional code may appear above
    app.alert({
        cMsg: "Value: "+value,
        cTitle: "Zone"
        app.beginPriv(); // Explicitly raise privilege
        app.launchURL(value);
        app.endPriv();
        // Additional code may appear below.
The Bookmarknames are:
Page 1
Page 2
Page 3
When I click a bookmark the script should launch a different URL like
http://localhost/directory/tPDF.php?p=0 if I click the Page 1 Bookmark name.
http://localhost/directory/tPDF.php?p=1 if I click the Page 2 Bookmark  name.
http://localhost/directory/tPDF.php?p=2 if I click the Page 3 Bookmark  name.
But I'm getting a strange behavior in this simple script:
The bookmarks always are sending the same URL.
http://localhost/directory/tPDF.php?p=2 if I click any Bookmark  name.
But the alert message in the web:
        app.alert({
         cMsg: "bookmark:  "+bkm.children[k].name+" trustedlURL("+p+")",
         cTitle:  "Testing"
the alert on the web is showing these values correctly
bookmark: Page 1 trustedlURL(0)
bookmark: Page 2 trustedlURL(1)
bookmark: Page 3 trustedlURL(2)
How is it posible the variable named "value" at the app folder-level script is always the same, the last p value used in the bucle, if the web script is changing value of variable "p" correctly.
"p" at the app folder-level script is always receiving the same value in the app.alert of the trustedFunction
http://localhost/directory/tPDF.php?p=2
and the URL launched when I click any bookmark is
http://localhost/directory/tPDF.php?p=2
instead of
http://localhost/directory/tPDF.php?p=0
or
http://localhost/directory/tPDF.php?p=1
or
http://localhost/directory/tPDF.php?p=2
I don't understand this behavior.
Any suggestions.

function(){return A.apply(null,[this].concat($A(arguments)))}
bkm.children[k].setAction("trustedlURL(p);");
In this case the function trustedIURL will be called with the last value of p.
You may try this:
bkm.children[k].setAction("trustedlURL(" + p + ");");

Similar Messages

  • Adobe Reader XI: FormBridge and TrustedFunction

    Hello
    We are using Formbridge to communicate with our Forms. So we load the Form with a XML file, to prefill the fields.
    With the update to Adobe Reader XI i can't get this working.
    I tried to add some specific policies with the ProtectedModeWhitelistConfig.txt, but that doens't work.
    [11:05/16:30:51] Found custom policy file: C:\Program Files\Adobe\Reader 11.0\Reader\ProtectedModeWhitelistConfig.txt
    [11:05/16:30:51] Adding custom policy: FILES_ALLOW_ANY = c:\*
    [11:05/16:30:51] Adding custom policy: FILES_ALLOW_ANY = d:\*
    [11:05/16:30:51] Adding custom policy: PROCESS_ALL_EXEC = c:\*
    [11:05/16:30:51] Adding custom policy: PROCESS_ALL_EXEC = d:\*
    [11:05/16:30:51] Adding custom policy: FILES_ALLOW_DIR_ANY = c:\*
    [11:05/16:30:51] Adding custom policy: FILES_ALLOW_DIR_ANY = d:\*
    [11:05/16:30:52] NtCreateKey: STATUS_ACCESS_DENIED
    Even the TrustedFunction SaveAs doesn't work.
    Can anyone help me plz? Thx...

    The FormBridge is the standard communication for Forms.
    In the FormBridge has a command to load an xml as stream parameter. An application manages the process to load the pdf with the specified xml:
    function loadXMLData(xmldata) {
        try{
            xfa.datasets.data.loadXML(xmldata, false, true);
        } catch (Ex){
            app.alert("Error in loadXmlData(); " + Ex);
    Te pdf is loaded into the Adobe Reader PlugIn for the browser.
    Beside the ProtectedModeWhitelistConfig it's all default.

  • JS Rename PDF using app.trustedFunction()

    I'm trying to create a simple rename Dialog that allows the user to rename the PDF and save it to a set folder location then close the doc.
    I'm getting this error in the console:
    this.saveAs is not a function
    4:App:Exec
    At the top of my script I have the trusted funtion:
    var JSRename = app.trustedFunction(function(myinfo)
    app.beginPriv();
    this.saveAs("/c/hold/"+ myinfo +".pdf");
    this.closeDoc(true); // close the doc, no notification
    app.endPriv();
    At the end of the Dialog code I call the trusted function:
    if("ok" == RenamePDF.DoDialog())
    JSRename(RenamePDF.stredt1);
    //console.println("edt1:" + RenamePDF.stredt1);
    At the bottom on the script I have the code to create a menu item that calles the Dialog:
    app.addToolButton({
    cName: "JSRename",
    cLabel: "JSRenamePDF",
    cEnable: "event.rc = (app.doc != null);",
    cExec: "MyRename();"});
    If I change my menu cExec to;
    cExec: "JSRename('test');"});
    My trusted function works fine. Is it possible to pass the value back from the Dialog tot he trusted fuction?

    Hi Aandi,
    If I run:
    var JSRename = app.trustedFunction(function(myinfo)
    app.beginPriv();
    this.saveAs("/c/hold/"+ myinfo +".pdf");
    this.closeDoc(true); // close the doc, no notification
    app.endPriv();
    app.addToolButton({
    cName: "JSRename",
    cLabel: "JSRenamePDF",
    cEnable: "event.rc = (app.doc != null);",
    cExec: "JSRename('myTestDoc');"});
    A menu button will appear and when I click it the active PDF docuemnt will be saved to the C:\hold\ folder as myTestDoc.pdf.
    I will do some alerts to check id the data in the Dialog is being passed to the trusted function.

  • Try to use trustedFunction

    var MyTrustedSaveAs = app.trustedFunction(function(?)
    app.beginPriv();
    this.saveAs("Something"); 
    app.endPriv();
    I would like to save my adobe form name and I want to use code I have there. Can someone tell what should I but there where I have ?...
    I am not familiar to this trustedFunction though can somebody tell me more about this method and also if know, tell me if this same work with reader also?
    When I use only
    this.saveAs("Something");
    then there comes error message
    NotAllowedError: Security settings prevent access to this property or method.
    App.trustedFunction:2:AcroForm:Button1:Annot1:MouseUp:Action1
    Thank you for your help!

    First of all thank you for your help.
    Can you tell me how I call my exempel my save.js from JavaScript folder. If I have this moseUp event. Is this JavaScript folder
    C:\Program Files\Adobe\Acrobat 10.0\Acrobat\Javascripts
    where I put my save.js.
    If I have this code here
    var MyTrustedSaveAs = app.trustedFunction(function(?)
    app.beginPriv();
    this.saveAs("Something"); 
    app.endPriv();
    Where I put that call and do I only save my save.js code to JavaScript folder to this form
    this.saveAs("Something"); 
    and then I only call it my trustedFunction.
    I would be very please if you can help me here.

  • Adobe Reader X: TrustedFunction SaveAs

    Hello
    I installed the new Adobe Reader X, and placed my TrustedFunction in the folder:
    C:\Program Files\Adobe\Reader 10.0\Reader\Javascripts
    When i test it, i always get the following error:
    Error in savePdfFile(); NotAllowedError: Secutiry settings prevent access to this property or method.
    i tried some settings in Adobe Reader X (like privileged locations) but nothing worked.
    TrustedSaveAsPdf.js
    trustedSaveAsPDF = app.trustedFunction(
      function (path){
            var retVal = "";
            app.beginPriv();
            retVal = event.target.saveAs(path);
            app.endPriv();
            return retVal;
    My Call:
    try {
       var retVal1 = trustedSaveAsPDF(<FILEPATH>);
    } catch (e) {
       app.alert("Error in savePdfFile(); " + e);

    Adobe Reader X runs in protected mode.
    http://learn.adobe.com/wiki/display/security/Protected+Mode+FAQ
    "Do plug-ins have read and write permissions to things like config files that maybe stored on the user's system?
    Plug-ins will not be able to write log files to non-whitelisted locations. They can continue to write logs to the Temp directory (as returned by GetTempPath() Windows API or equivalent Acrobat API). Another white-listed location is Adobe Reader's own appdata area."
    You can write out silently only to the whitelisted locations. The other alternative is to throw a save as dialog for user to select the location and save.

  • Correct use of app.trustedFunction ?

    Hello,
    I have a function1 which launch a diaglog when a user clicks on the button. Function1 is in the folder script.  For the click event, I have: script1.function1();
    However, the dialog box has the title "JavaScript Window" and the warning "Warning: JavaScript Window".
    I searched and follow the suggestion in the forum.  I created a app.trusted fuction as below:
    var vDialog = app.trustedFunction(function() {
          app.beginPriv();
          launchDialog();
         app.endPriv();
    In the click event, I have:
         event.target.vDialog();
    However, this doesn't work.  Could someone points out for me where the mistake is?  Also, is there a way to change the windown title, instead of "JavaScript Window", it says "Help Information"?
    Thank you.

    You might want to look at the documentation for the app.trustPropagatorFunction:
    http://livedocs.adobe.com/acrobat_sdk/9.1/Acrobat9_1_HTMLHelp/JS_API_AcroJS.88.168.html
    Example #2 shows how you can prevent the JavaScript warning in the title. To set the title of the dialog, set the "name" property (in the description object) to the string you want to use.

  • How can I add form field value to the file name in save as dialog box

    I do not want the form to be saved automatically, just want the form to auto populate the "file name" only.
    A little background on the forms I want to use:  My company has 70 retail outlets, I'll use one of our pdf forms called an "Incident Report" as an example.  I would like for a store manager to be able to complete the form, then email the form to the main office (I already have javascript to add field values and form name to the email subject line), once the main office receives it, I want for them to be able to file the pdf electronically on our server.  We have mutliple forms that we use so I do not want any of the forms to automatically save anywhere, (at this time anyway) I just want the office personnel to be able to click "save as" (or whatever they will need to click) and the form automatically add certain field values from the pdf they have received, of which will be different each time the form is sent to the office (Date, store #, employee name etc.) in addition to the name of the form in the "File name" of the "Save As" dialog box.  The main office employees will decide into which server file the pdf should be saved.
    I'm using Acrobat 8 professional, the stores and office personnel use Adobe reader.
    One little note:  We currently print and file a lot of paper on a daily bases, as soon as I can get this to work, we are going green.
    Me and a lot of trees in this will really apprecitate any help you can give with this!  :-)

    You might want to take a look at the document "Developing Acrobat Applications Using JavaScript" (js_developer_guide.pdf) which is part of the Adobe Acrobat SDK, which can be downloaded here. Read the "Privileged versus non-privileged context" (p. 45ff.). You will find an example for "Executing privileged methods in a non-privileged context". Should be almost exactly what you are looking for.
    Small Outline: For security reasons ("the user always has to know what's going on") you are not allowed to use the "Doc.saveAs"-method without the user permission (--> in a non-privileged context). In order to reach the goal of a privileged context you can use a trusted function. You do this by creating a JavaScript file (*.js) in either the Application-JavaScript-Folder (default location on Windows systems: "%ProgramFiles%\Adobe\Acrobat 10.0\Acrobat\Javascripts") or the User-JavaScript-Folder (default location on Windows systems: "%AppData%\Adobe\Acrobat\10.0\JavaScripts"). Add the following content to the new file:
    myTrustedBrowseForDoc = app.trustedFunction( function ( oArgs ) {
         app.beginPriv();
              var myTrustedRetn = app.browseForDoc( oArgs );
         app.endPriv();
         return myTrustedRetn;
    myTrustedSaveAs = app.trustedFunction( function ( doc, oArgs ) {
         app.beginPriv();
              var myTrustedRetn = doc.saveAs( oArgs );
         app.endPriv();
         return myTrustedRetn;
    The developer guide actually wants you to add this content to the existing "config.js" file. I recommend creating a new file, since its easier to deploy in a network. Either way, every client/user who needs to be able to save documents this way, needs this JavaScript Code in his Application/User-JavaScript-Folder.
    Within the Acrobat Document, which you want to obtain a certain file name, you can now use the trusted functions "myTrustedBrowseForDoc" and "myTrustedSaveAs" to store the file. To call the trusted functions and deliver the file name you can either you use a form field (button) or you add a new menu item. Add the following JavaScript Action to the button/menu item and change "Roller Coaster" to the name of the field which contains the value which you want to become the new file name:
    var fileName = this.getField("Roller Coaster").valueAsString;
    try {
         var oRetn = myTrustedBrowseForDoc({bSave: true, cFilenameInit: fileName + ".pdf"});
         try {
              myTrustedSaveAs(this, { cPath: oRetn.cPath, cFS:oRetn.cFS });
         catch(e) {
              console.println("Save not allowed, perhaps readonly.");
    catch(e) {
    console.println("User cancelled Save As dialog box");
    Good Luck!

  • Folder level script? How can I use field value as a pdf filename in save as dialog box

    I read somewhere that if you use a folder level script, you can do things like save a pdf with a specific filename - possibly based on a field name.
    How would one set up a folder level script?
    How do you execute a script from the PDF?
    What code would you use to change the PDF name to the contents of the fFieldName text field?
    Or, is this really just impossible to do?

    The article is interesting.  It suggests you place code like this:
    // Page Replacement Function
    var ReplaceLastPage = app.trustedFunction( function(cPath) {
    app.beginPriv();
    this.replacePages(this.numPages-1, cPath); app.endPriv();
    In the trusted folder.  What is the path of the trusted function(s) that get automatically loaded into Acrobat?
    I assume in the example above, function(cPath) is a function inside of the PDF...

  • Why do I have to run a  doc.saveAs() prior to Inserting, Deleteing, or Extracting pages?

    MY SETUP:
    I'm using folder level javascripts.   In Acrobat I have the 'enable menue items javascript execution privledge' enabled,  In my actual folder level scrips I have them wrapped in a trusted function along with app.beginPriv()/app.endPriv().    My PDF's are coming from LiveCycle Designer which I then open and run in Acrobat.
    MY QUESTION:
    Through much trial and error and banging my head on the wall I've found that if I want to use insertPages(), extractPages() or deletePages() called as a trusted fucntion  on its own it won't work unless I first run a saveAs() function to create a new document file and only then can I run the desired function on the new saveAs'd doc.   I simply can't run an insertPages() on the current open doc without a saveAs first().    
    Why is that?
    I find that very frusterating and the resulting errors aren't a help.  If I don't SaveAs first I get security error or invalid function errors.
    EXAMPLE:
    Save As Function:
    var LCB_SaveAs = app.trustedFunction(function(doc, filename) {
        app.beginPriv();
        doc.saveAs(filename);
        app.endPriv();
    Insert Page Function:
    var TEST_InsertPage = app.trustedFunction(function(doc, filename) {
        app.beginPriv();
           doc.insertPages ({
               nPage: -1,
               cPath: filename
           app.endPriv();
    Javascript code in document to call the above functions:
    if(typeof(LCB_SaveAs) == "function") {
        if(typeof(TEST_InsertPage) == "function") {
            try {
                TempFileLocation = "/C/PATH/InsertTemp.pdf"
                LCB_SaveAs(event.target, TempFileLocation);
                try {
                    PathOfInsertDoc = "/C/PATH/FileToInsertIntoSaveAs'dDoc.pdf"
                    TEST_InsertPage(event.target, PathOfInsertDoc)
                catch(e) {
                    xfa.host.messageBox(e.toString().replace("RaiseError: ","") , 0, 0); 
            catch(e) {
                xfa.host.messageBox(e.toString().replace("RaiseError: ",""), 0, 0); 

    Hi George.  Yes I'm using static XFA forms which were created with PDF's as basic 'artwork' in the background and then my custom fields and script tunning on top. 
    I've tried running  a function (below) in the console, but did nothing -- maybe a syntack error.  I don't know what that may or may not mean though.  I'm not use to running stuff through the console so I could be doing it wrong.  My console experiance is limited to calling the path where the javascripts folder resides.
    Attempt script in console:
    var MJS_HN_Delete_RevisitForm = app.trustedFunction(function(doc) {
        app.beginPriv();
        doc.deletePages(15, 15);
        app.endPriv();
    and/or this:
    app.trustedFunction(function(doc) {
        app.beginPriv();
        doc.deletePages(15, 15);
        app.endPriv();

  • Problem with SaveAs function using random paths.

    The Setup:
    Part 1) I have a folder-level script that allows me to perform a SaveAs function from within forms. I do this as a way to save the document quietly in the background. The effect is that the file is overwritten by a copy of itself. The script is:
    var mySaveAs = app.trustedFunction( function(oDoc,cPath,cFlName)
        app.beginPriv();
        cPath = cPath.replace(/([^\/])$/, "$1/");
        try{
            oDoc.saveAs(cPath + cFlName);
        }catch(e){
            app.alert("Error During Save");
        app.endPriv();
    Part 2) From within my documents, I perform the save by calling the function below:
    function runSave()
    {if(typeof(mySaveAs) == "function") {
        var pathArray = this.path.split("/");
        var myFileName = pathArray[pathArray.length-1];
        var cPath = this.path.slice(0,myFileName);
        mySaveAs(this, cPath, myFileName);
    } else {
        app.alert("Missing Save Function\n" + "Please contact forms administrator");
    Part 3) I have several large forms that utilize an autosave to call the save function according to a time interval of 5 minutes, using:
    app.setInterval(runSave(), 300000);
    The Problem:
    Part 1) The autosave feature works fine and it works silently in the background. However, I start to experience problems when I have two forms open at the same time. If, for example, I have a form from one folder open, and open a form from a second folder, the save feature will sometimes save the active document to it's original folder (as intended, overwriting itself and creating an autosave) or sometimes save to the second document's original folder. This leaves me with an updated (autosaved) copy of the document in the wrong folder, and a non-updated copy in the original folder. This seems to vary depending on which document I opened last and/or which document is currently active. Though I can't seem to find the right combination.
    It's as thought the "this.path" is getting confused.
    Part 2) Worse still, if the two documents have the same name, as is often the case with these forms, any incorrect filing when saving causes an overwrite of the second document and loss of data.
    Part 3) To makes things maddening, this also happens at times when no second folder or second document is open. Instead, the misfiling saves the single, active document to a recently accessed folder. For example, I'll open a local folder and open a Word doc, close the doc and the folder, go to a different folder in a different root (a networked folder), open the form, and it autosaves to the local machine in the folder with the Word doc. So now not only do I have a non-updated copy in my correct folder, I have no idea where the updated copy was actually saved to until I come across it some time later.
    Part 4) Again, worse still, the previously accessed folder might happen to be one that contains a document with the same name, and that document gets overwritten by the autosave. I'll have no idea that the form has been overwritten until I happen to open it some time later and see that it contains data from a totally different form.
    What is going on and how do I stop it?
    Adobe Acrobat X Pro on a PC.

    Thank you, that is helpful to understand. I'd like to keep it as 3 parameters, as all my documents currently output 3 to the trusted function. And I'd still like to keep the error catch, but I'm not sure why the previous trusted function from the tutorial is no longer working, so I just want to run this by you:
    safeSaveAs = app.trustPropagatorFunction(function(theDoc,thePath,theFileName){
        app.beginPriv();
        var fullPath = (thePath + theFileName);  
        try {
            theDoc.saveAs({cPath:fullPath});
        } catch(e) {
            app.alert("Error During Save");
        app.endPriv();
    myTrustedSaveAs = app.trustedFunction(function(theDoc,thePath,theFileName){
            app.beginPriv();
            safeSaveAs(theDoc,thePath,theFileName);
            app.endPriv();

  • Print to PDF and specify file name.

    Hardware/Software Details:
    MacBook 2GHz Intel Core 2 Duo
    OS 10.5.5
    Adobe Acrobat Professional 8.1.2
    Hey all,
    I'm a teacher and I've been scripting PDFs for use as marking sheets for assignments. What I'm trying to achieve is a situation where I tick all the boxes, marks are calculated and comments filled-in using my form fields (which all work fine) and then produce a PDF from that file with the student's name as the new file name (which is where I'm stuck!).
    In the past, I've had a button that on mouseOver brings the field with the student's name into focus, mouseDown evoked the File:Copy menuItem (copying the student name to the system's clipboard) and then mouseUp which triggered File:Print from which I would choose 'Adobe PDF 8.0' as the printer, hit Save, paste the student's name as the file name and choose the appropriate directory.
    File:Copy is no longer a "safe" menu item according to the latest versions of Acrobat, so I'm having to manually copy the name which is complicating the process further.
    I'm working on a script activated by the mouseUp of a button in this PDF which is currently looking like this:
    >var pp = this.getPrintParams();
    // format name to remove spaces and commas
    var studName = this.getField("Name").value.split(",").join("_").split(" ").join("");
    pp.interactive = pp.constants.interactionLevel.silent;
    pp.printerName = "";
    pp.fileName = studentName + ".ps";
    this.print(pp);
    Although the console will list 'AdobePDF8' as one of my printers, I've since discovered that "the destination printer cannot be set through this property in Mac OS" :( . I can set it as my default printer to work around it, but I still can't dictate the name of the new file. So, I've resorted to printing to PostScript with the aim of running them all as a batch through the AdobePDF8 printer later, except there's still a few problems.
    The name of the PostScript file won't work when I try to include the value of another variable (var studentName)
    The fonts in the PostScript files that it does produce get substituted with Courier and look terrible
    Both the API Reference and the Developer Guide seem to indicate that you can print to a file rather than a printer, but both only seem to mention PostScript file using this method.
    Is there another way to do this? If not, is there a solution to the two problems I mentioned?
    Cheers,
    Chris

    Ok, I've pursued the SaveAs method (as George suggested) with moderate success with the following code (secure function names have been changed ;) ):
    config.js file script:
    >myTrustedSaveAs = app.trustedFunction( function ( doc, studName )
    app.beginPriv();
    doc.saveAs({
    cPath: studName,
    bCopy: true,
    bPromptToOverwrite: true
    app.endPriv();
    myTrustedOpenDoc = app.trustedFunction( function ( path )
    app.beginPriv();
    app.openDoc({
    cPath: path
    app.endPriv();
    Button's onMouseUp script:
    >// get student name and turn it into a file name
    var studFile = this.getField("Name").value.split(",").join("_").split(" ").join("") + ".pdf";
    // get the current document's directory path
    var origFile = this.path;
    var pathBits = this.path.split("/");
    pathBits.pop();
    // whack 'em together
    pathBits.push(studFile);
    var studFilePath = pathBits.join("/");
    // toss the form fields and stuff
    this.flattenPages({
    nNonPrint: 2
    // save the new file
    myTrustedSaveAs(this,studFilePath);
    // open the original again (not working)
    myTrustedOpenDoc(origFile);
    // close the one I just saved
    this.closeDoc(true);
    This is what happens:
    Button is clicked,
    All the form fields and buttons are removed,
    It produces a file with the new file name (e.g. Lawrence_Chris.pdf) next to the original,
    The file closes
    I'm pretty sure that once the SaveAs runs and the new file is created, I actually still have the original file open instead of the that was just saved. This would explain why the openDoc command doesn't seem to do anything because the file it's opening is already open. The closeDoc then runs and of course I then have no open documents!
    So, now I either need a way to revert the open original file so I get all of my form fields back and don't have to reopen it, or a way to close and then immediately open the file without saving changes. :/
    Any ideas?
    slight inconvenience of needing a separate .js file written for the user's JavaScript folder before launching Acrobat to overcome security restrictions. File sizes only seem to get down to about 376KB as opposed to the 40KB files that the AdobePDF8 printer spits out. :(

  • I can't create a javascript saveas for radiobox

    I started this discussion in acrobat windows forum and I think I should have put it here so I'm reposting it.
    First, I want to say thanks for helping.
    I  am new to javascript and coding in general, but I feel that I have been  learning and picking up the coding from sites like this.  I am making a  form using adobe acrobat pro 3D 8.1.0.  I have a combobox that I have a  list of a bunch of locations.  The combobox is set to export a 3 or 4  letter or digit result that is unique to that site.  I have then set up a  saveas on blur following the selection.  This is all working correctly.
    However,  I several hundred radioboxes and textboxes in the document.  This  document will be used for acceptance testing and I do not want to  accidentally lose any data so I want to save after every selection or  input in the textboxes.
    The following is my code for the combobox.
    // build file name
    var site = this.getField("siteName").valueAsString;
    Date.prototype.defaultView=function(){
    var dd = this.getDate();
    var mm=this.getMonth()+1;
    var yyyy=this.getFullYear();
    return String(mm+"-"+dd+"-"+yyyy)
    var today = new Date();
    var gmtHours = -today.getTimezoneOffset()/60;
    var cstHours = today.getUTCHours() + gmtHours;
    if(cstHours<10)cstHours='0'+cstHours;
    var min = today.getUTCMinutes();
    if(min<10)min='0'+min;
    var sec=today.getUTCSeconds();
    if(sec<10)sec='0'+sec;
    var timeStamp=today.defaultView() + "_" + cstHours + "-" + min + "-" + sec;
    var myFileName = site + "_" + timeStamp + ".pdf";
    // add folder name
    myFileName = "/f/file_test/" + myFileName
    myTrustedSpecialTaskFunc(this, myFileName);
    this.getField("docName").value = myFileName;
    I  was struggling with the saveas and I don't want to create a new file  everytime so I created a hidden textbox that has the file name.  I was  hoping that I could just read this textbox and saveas using the original  filename.  (The script above uses time in the filename so that would  create a new file name every second)  The hidden text box is getting the  values correctly and is working fine.
    I have tried  several different methods of javascript on the radio buttons and text  text boxes.  On the radio button I have tried all mouse options, but I  was hoping to use mouse up.  The textboxes I want to use mouse, on  blur.   Below is some of the scripts that I have tried.  I want it to be  automatic and I want it to overwrite everytime without prompts.
    app.execMenuItem("Save");
    var oMyDoc = <… PDF being operated on …>
    app.execMenuItem("Save", oMyDoc);
    var myFileName = this.getField("docName").valueAsString;
    this.saveAs(myFileName);
    ....and I have tried others, but since they didn't work, I didn't keep track of them.
    I appreciate any suggestions!
    Thanks

    George, thanks for the reply.  I am new to coding and I really don't know much about folder level scripts.  However, I did create the following trusted saveas script which I saved as a .js in adobe.  Is this what you are refering to?
    mySaveAs = app.trustPropagatorFunction(function(doc,path) {
    app.beginPriv();
    doc.saveAs(path);
    app.endPriv();
    myTrustedSpecialTaskFunc = app.trustedFunction(function(doc,path) {
    // Privileged and/or non-privileged code above
    app.beginPriv();
    mySaveAs(doc,path);
    app.endPriv();
    // Privileged and/or non-privileged code below
    I did try refering back to this script once, but I wasn't able to get it to work.

  • Doc Save As and Trusted Function

    I have been reading over the forum and the adobe help files regarding this. I think I am close but since I need to get my IT department to assist in placing the js files where they have to go, I thought I might ask the forum if I am on the right track
    I still have to make sure the field values will not include an illegal characters. They wont be empty as the forms will be coming directly from our system -prefilled
    Currently these forms automatically email (although staff still have to hit the actual send button) when staff go to print the document.  The people who get these forms are just finding it a bit hard to keep up with the emails and have asked to just have the files save to a folder so they can look at when they have time
    This is what I have for my trust propagator function.  I assume this is the only js file I will need as it incoporates the trusted function?
    mySaveAs = app.trustPropagatorFunction(function(doc,path)
      app.beginPriv();
       doc.saveAs(path);
      app.endPriv(); })
    myTrustedSpecialTaskFunc = app.trustedFunction(function(doc,path)
      // Privileged and/or non-privileged code above
      app.beginPriv();
       mySaveAs(doc,path);
      app.endPriv();
      // Privileged and/or non-privileged code below });
    I got this code from the Adobe Help
    then I want to have this code in the Document Did Print area
    var name = this.getField("FormValues.accountNames_0").value
    var folio =this.getField("FormValues.folioNumber_0").value
    myTrustedSpecialTaskFunc(this, "/w/Public/AccountOpening/" + name + " " + folio,pdf);
    I have to read where to put the js file as I have seen some comments on the forum that where you place the js file has changed for those with Adobe X and Windows 7
    Would anyone be be able to let me know if I am on the right path before I get IT involved.  I suppose I could test the code on my own laptop to see if it would allow me to save the form.....
    Thank you

    Read this: The Acrobat Ninja: Acrobat 10.1.1 JavaScript changes
    You have to manually create the folders that aren't present, and they must be named correctly.
    It's a good idea to use the valueAsString property instead of the value property to get the field values, since you're using the results as strings. It probably won't make a difference here, but it's a good habit to get into. You also have a typo in that last line of code. It should be:
    myTrustedSpecialTaskFunc(this, "/w/Public/AccountOpening/" + name + " " + folio + ".pdf");
    It would be a good idea to make sure those field value aren't blank if there's a chance that they could be.
    Also, consider using a try/catch block for the doc.saveAs call, and look at the return value so you can give the users a more helpful error message than what the default will be if something goes wrong.
    If you need help with any of this, post again.

  • How to Display Windows Username in a PDF File?

    I have a PDF form, it has a Name and a Date field, I setup the Date to display todays Date automatically using JavaScript. Now since my users have unique Windows login names. I want to automatically display there username or Windows name in the Name field. Can I do this using JavaScript? or is there a different way? Any help would be greatly appreciated.

    Here's a barebones script that you can call from a script in your form to retrieve the login name of the user:
    // Folder-level JavaScript function
    var getLoginName = app.trustedFunction(
        function () {
            // Get and return the user's login name
            app.beginPriv();
            return identity.loginName;
            app.EndPriv();
    This needs to be included in a JavaScript file that's installed in the correct location. It's just a text file, so you can create/edit it with a text editor, but make sure the extension is ".js". For more information about how to determine where to place the file, see: http://acrobatusers.com/tutorials/2006/folder_level_scripts
    More information on all of this is in the Acrobat JavaScript reference: http://www.adobe.com/devnet/acrobat/javascript.html
    To populate a text field with the login name, do something like:
    // Populate field with loginName
    getField("text1").value = getLoginName();
    Change "text1" with the actual name of the field in your form. You can place this code in a document-level JavaScript so it executes when the form is opened.
    Note that all of this code is the bare minimum, and you may want to expand it to check for errors, etc.

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

    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();

    I have found the error, you are quite correct I had an extra letter in the filename, I thought I'd checked this but just shows that sattention to detail is the key.
    The script works perfectly now, thanks you for your help, really appreciated.
    Thanks again
    Ben

Maybe you are looking for

  • I just updated to 3.6.11 and now firefox won't load any web page

    I just updated to 3.6.11 and now firefox won't load any webpage it just times out I tried diableing add-ons no difference. I't on internet exploers now. Tried rebooting.

  • How do get my music from my ipod to my library.

    I swiped my computer a few days ago and i was woundering if i could just move the music from my ipod to my library, iv ben looking but i havent found anything, or do i need to just reload everything(if i reload everything will i lose my purchased mus

  • Is it a bug? CS5

    Hi! Having some serious trouble in cs5. When moving objects, they don't stay where I try to put them, but rather jumps a little to the side. It happens booth with and without "smart guides" (It does not occur when trying with box-shaped objects) This

  • 3d parsing error

    When  we try to open our solid models converted to pdf we are getting this error "A 3d parsing error has occured". Thes files all worked before and now everyone is having problems. Loaded version 9.5.5. and 11.

  • When validate item not firing when exit with mouse

    Hi I have a when validate item tirgger on an item. it fires fine when I use tab from keyboard after validating but when i navigate to another field with the mouse, the trigger does not fire. it only fires when i try to close the window.. how can i ov