Skip navigation
Owlbert358
Currently Being Moderated

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

Feb 15, 2012 11:13 AM

Tags: #javascript #reader #acrobat-forms #acrobat_professional #pdf_

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!  :-)

 
Replies
  • Currently Being Moderated
    Feb 15, 2012 12:30 PM   in reply to Owlbert358

    You can't pre-populate the name that appears in the Save As dialog.
    What you can do, though, is save the file using a new name. However, this requires a script to be installed on the local machine of each user who's going to be using this file. If that's a possibility for you, we could discuss it further.

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 12, 2012 8:31 PM   in reply to Owlbert358

    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!

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 13, 2012 7:14 AM   in reply to FrogThomas99

    The OP is using Acrobat 8, so the location of files as needed by Acrobat X will not work.

     

    If you are using scripts with the  "privileged"  method in Acrobat X you should be aware of the JavaScript Changes for Acrobat X and Reader X, version 10.1.1 and User JavaScript Changes for 10.1.1 (Acrobat | Reader).

     

    How to save a PDF with Acrobat JavaScript by Thom Parker provides a lot of information you need to know like the safe paths, how to get file folder locations for JavaScript through use of the JavaScript console, the universal path directory format, and other items you need to be aware of.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (1)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points