Using javascript to save a pdf to a different directory and generating a new filename based on form fields in the document.

I have built the following script in an attempt to create a submit button that will automatically save the document in a different directory on my computer. It will also use the form field data "customer" and "date" to generate the filename. I printed out the variable myPath and it looks like it printed the correct string. I keep getting the following error:
TypeError: redeclaration of const path
any help would be much appreciated.
var customer = this.getField("Customer").value;
var date = this.getField("Date").value;
var path = "C:/Users/awilliams/My Documents/Test/"
  var reg = date.match(/(\d+)\/(\d+)\/(\d+)/);
var myPath= "C:/Users/awilliams/My Documents/Test/" + customer + "_" + reg[1] + "." + reg[2] + "." +
reg[3] + ".pdf";
this.saveAs(myPath);

"path" is a keyword within a PDF you should not use keywords as a name for any other object as a general rule.
Have you checked the PDF Reference to see how to create a file path name within a PDF,  3.10.1 File Specification Strings page 118?
Did you carefully read the Acrobat JavaScript Reference for the saveAs method?
The notes following the description:
Note: This method can only be executed during a batch or console event. See Privileged versus non-privileged context for details. The event object contains a discussion of JavaScript events.
(Adobe Reader S): This method is available in Adobe Reader for documents that have Save usage rights.
How to Save a PDF with Acrobat JavaScript

Similar Messages

  • Save As with the filename from a form field entry

    Hi,
    I have an Acrobat fillable form. It is a questionaire that will be filled out by visitors using my laptop then printed. It is important that this form also be saved so I can later merge the data to a spreadsheet.
    My first thought was to create a button labeled Print that would first do a Save As then Print. But I'm concerned the visitor may mislabel or even escape out of the Save As dialog box.
    Is there java script code someone could help me with that would perform the Save As using the data imputted into one of the form fields as the filename. So when the Print button was clicked the form would be saved (behind the scene) and then printed.
    Thanks
    Dennis

    Issue solved. I should've used Display as text (Does not save state)
    THANK YOU JOEL!
    Anca

  • Unable to fill out interactive form fields in the pdf form.

    I'm unable to fill out interactive form fields in the pdf tax form in Reader 11.0.06 with purple bar inviting to do so.

    The only Flash Player that is remotely connected to Adobe Reader is the plugin.
    Can you temporarily uninstall the plugin (or both ActiveX and plugin using http://helpx.adobe.com/flash-player/kb/uninstall-flash-player-windows.html and see if the problem disappears?
    Reinstall both using these installers http://helpx.adobe.com/flash-player/kb/installation-problems-flash-player-windows.html#mai n-pars_text_4

  • I have protected pdf files. You can not copy things, but it is allowed to print. In the menu of the pdf it says you are allowed to print. I already printed lots of times the document. But today there is an error "The printer is not admittet to print these

    I have protected pdf files. You can not copy things, but it is allowed to print. In the menu of the pdf it says you are allowed to print. I already printed lots of times the document. But today there is an error "The printer is not admittet to print these pdf". Its new. Theres no problem with the printer. I can print word documents, internet pages etc. But today I can not print anymore my pdf document, although printing is allowed and only copying is forbidden.
    How to solve the problem with the pdf?
    Thank you.

    Hi Hans,
    There seems to be other restrictions in the document that's not allowing it to print.
    Would it be possible to share the document with me so that I can have a look?
    Regards,
    Rave

  • I want read PDF file from SAP directory and create a spool request or print

    Hi all,
    I want read PDF file from SAP directory and create a spool request or print the pdf through SAP. Can any body  help me in this.
    Also please write to me if its possible to open PDF from SAP directory to adobe pdf reader.
    Thanks in advance,
    Sunny

    Hi Sunny,
    Check these links.
    http://www.sapdevelopment.co.uk/reporting/rep_spooltopdf.htm
    http://www.erpgenie.com/sap/abap/pdf_creation.htm
    http://www.geocities.com/mpioud/Z_EMAIL_ABAP_REPORT.html
    http://www.thespot4sap.com/Articles/SAP_Mail_SO_Object_Send.asp
    http://www.sapdevelopment.co.uk/reporting/email/attach_xls.htm
    Hope this resolves your query.
    Reward all the helpful answers.
    Regards

  • Using Itunes, I copied all my apps from my Ipod touch to a new Iphone 4. Problem is all the apps on the Iphone are starting up like a new install. I would think my "password" app and "lose it" app would have the past data transferred to the Iphone.

    Using Itunes, I copied all my apps from my Ipod touch to a new Iphone 4. Problem is all the apps on the Iphone are starting up like a new install. I would think my "password" app and "lose it" app would have the past data transferred to the Iphone. Is this not possible??

    Try this Discussion...
    https://discussions.apple.com/message/19529357#19529357

  • I have switched the sim card from one iphone to a different one, and i added my music from my old phone to the used one, now the old music on the used phone won't delete. im really frustrated and annoyed please help

    i have switched the sim card from one iphone to a different one, and i added my music from my old phone to the used one, now the old music on the used phone won't delete. im really frustrated and annoyed please help

    Do you just want to delete the music or wipe the whole phone since you've switched to the other one?
    If you plug the old iPhone into your computer you can remove stuff via iTunes or remove stuff directly from the iPhone too.

  • How to get an Adobe trusted function javascript to save a pdf form even if fields are empty?

    I have a form I have created in Livecycle designer which I want to save to a specific location using a combination of specific fields in the form. I have been able to do this by writing a trusted function and putting it in the adobe javascript file and then putting some code on a save button in the form. However, it may be that some of the fields (vfirstname and vsecondname) may be blank and i still want the form to save. Ideally i want to write an if statement to substitute those fields for other fields if they are blank but cant get the code to  work.
    Working code in trusted function file
    // SaveAs Function1 var mySaveDoc = app.trustedFunction(function(doc) { app.beginPriv(); var vDate1 = event.target.xfa.resolveNode("form1.page1.Table1.Row1.leftsideofform.Timeanddate.Dateofca ll").rawValue.toString(); var vfirstname = event.target.xfa.resolveNode(" form1.page1.Table1.Row1.rightsideofform.Prospectiveclient.ClientFirstname").rawValue.toSt ring(); var vsecondname = event.target.xfa.resolveNode("form1.page1.Table1.Row1.rightsideofform.Prospectiveclient.C lientsurname").rawValue.toString(); var myPath = "/MGLCC01-SV/MGPdata/Mihomecare/testce/" + vDate1 +"_" + vfirstname + "-" + vsecondname + ".pdf"; // saveAs is the only privileged code that needs to be enclosed doc.saveAs({cPath: myPath, bCopy: true, bPromptToOverwrite: true}); app.endPriv(); }); 
    Working code on save button in form
    form1.#pageSet[0].Newenquirymasterpage.Button1::mouseUp - (JavaScript, client) var txt = form1.execValidate(); //This script will validate all required fields event.target.mySaveDoc(event.target) xfa.host.messageBox("Document has been saved to shared drive", "File Saved", 3, 1); 
    IF code for trusted function file that I cant get to work
    // SaveAs Function1 var mySaveDoc = app.trustedFunction(function(doc) { app.beginPriv(); var vDate1 = event.target.xfa.resolveNode("form1.page1.Table1.Row1.leftsideofform.Timeanddate.Dateofca ll").rawValue.toString(); if (event.target.xfa.resolveNode("form1.page1.Table1.Row1.rightsideofform.Prospectiveclient. ClientFirstname").rawValue == " ")      {          var vfirstname = event.target.xfa.resolveNode("form1.page1.Table1.Row1.rightsideofform.Enquirer.EnquFirstn ame").rawValue.toString();      }      else      {          var vfirstname = event.target.xfa.resolveNode("form1.page1.Table1.Row1.rightsideofform.Prospectiveclient.C lientFirstname").rawValue.toString();      }     if (event.target.xfa.resolveNode("form1.page1.Table1.Row1.rightsideofform.Prospectiveclient. Clientsurname").rawValue == " ")      {          var vsecondname = event.target.xfa.resolveNode("form1.page1.Table1.Row1.rightsideofform.Enquirer.Enqsurname ").rawValue.toString();      }      else      {          var vsecondname = event.target.xfa.resolveNode("form1.page1.Table1.Row1.rightsideofform.Prospectiveclient.C lientsurname").rawValue.toString();      } var myPath = "/MGLCC01-SV/MGPdata/Mihomecare/testce/" + vDate1 +"_" + vfirstname + "-" + vsecondname + ".pdf"; // saveAs is the only privileged code that needs to be enclosed doc.saveAs({cPath: myPath, bCopy: true, bPromptToOverwrite: true}); app.endPriv(); }); 
    Can anyone suggest why the If code above doesn't work? or how i could get the form to submit even if the fields are blank?

    It can also work if you certify the document and each user chooses to trust it to execute privileged JavaScript, which may be feasible in this setting. The method you'd use is doc.saveAs: http://livedocs.adobe.com/acrobat_sdk/9.1/Acrobat9_1_HTMLHelp/JS_API_AcroJS.88.524.html
    Also, read the following tutorial: http://acrobatusers.com/tutorials/how-save-pdf-acrobat-javascript

  • How to use javascript to "save as" using form data in the file name

    I want to be able to use a button to "save as" and have it automatically pick up and use certain data from the fields in the file name. without having to manually type in the file name.
    Name: john doe
    Date: 1-25-13
    file name would be  (john doe 1-25-13)

    You will need two parts for this. A folder level script (which you place in a .js file under the JavaScripts folder of Acrobat), and a script embedded in the file itself (probably attached to a button).
    The folder-level script will look like this:
    var mySaveAs = app.trustedFunction( function(oDoc,cPath) {
        app.beginPriv();
        try {
            oDoc.saveAs(cPath);
        } catch(e){
            app.alert("Error During Save");
        app.endPriv();
    The doc-level script can look something like this (of course, you might need to adjust the names of the fields used):
    var filePath = this.path.replace(this.documentFileName, "");
    var newFileName = this.getField("name").valueAsString + " " + this.getField("date").valueAsString + ".pdf";
    mySaveAs(this, filePath+newFileName);
    You should be aware that several characters are not allowed in the file name, including comma's, forward- and back-slashes, line-breaks and excalmation marks, so if you try to use them the script would fail. It is possible to create a more advanced version of this script that will automatically remove such characters from the file-name, or alert the user if they used them.

  • Need File-Save as-PDF as a toolbar button and one item on menu

    What I'd like to see is a single menu line item and button added for File ->Save as ->PDF.  Right now, you have to open three menus to perform this function,and there is not a toolbar button offered at all.  Every document I save in this program is in PDF format, so it is frustrating to have to perform this action every time.  There are keystroke combinations (Shift + Control + S) but I tend to use the mouse more than the keyboard.

    Here's some barebones code to add a Save As toolbar button. It goes in a folder-level JavaScript file that you have to create and install properly:
    var mySave2 = app.trustedFunction(function(doc) {
        app.beginPriv();
        var oFS = app.browseForDoc({bSave: true, cFilenameInit: doc.documentFileName, cWindowTitle: "Save As"})
        if (oFS) {
            doc.saveAs({cPath: oFS.cPath});
        app.endPriv();
    app.addToolButton(
        cName: "ToolbarSaveAs2",
        cLabel: "Save As",
        cExec: "mySave2(this);",
        cEnable: "event.rc = app.doc;"
    For more information on folder-level scripts, see: http://acrobatusers.com/tutorials/print/entering-folder-level-scripts
    and for updated info, see: http://acrobatninja.blogspot.com/2011/09/acrobat-1011-javascript-changes.html
    As Dave mentioned, in Acrobat 10 you'll have to add the new button from "Tools > Add-on Tools" to the Quick Tools toolbar by right-clicking it and selecting "Add to Quick Tools Toolbar".

  • I would like to know why when i make a web page and test in my local browser it works fine then when i tranfer to my server i does not work fine example i used javascript to put a prompt bar on a page and it worked fine local but on server not working

    how come when i make a web site and i test it in my local server it works fine when i tranfer to server certain things do not work example i used javascript to put in a prompt bar for a newsletter page at the server it did not work but at local it did also it works at MOZZILLA but not internet explorer i also have cs4 was wondering if there is a way to test a page in dreamweaver and then transfer   THANK YOU X-FACTOR-MEDIA

    In future, please try to make the subject line of your posts shorter. In this case the following would have been sufficient: "JavaScript works locally, but not on remote server".
    Short, but meaningful subject lines make it easier for others to identify what your question is about, and often bring faster help.

  • Automatically Name Document using form fields in the PDF?

    Is it possible to populate the Save Name field with a concatenation of fields that the user selects on a form? I'm using Reader Extensions to let a user fill out a form and save it, and I have 3 fields - Station, Month and Year, in the document. (It's a monthly report) I'd like it when the user goes to save the document to have it automatically named "WGST October 2007" - the concatenation of those 3 fields.
    Thanks in advance!!

    The only Flash Player that is remotely connected to Adobe Reader is the plugin.
    Can you temporarily uninstall the plugin (or both ActiveX and plugin using http://helpx.adobe.com/flash-player/kb/uninstall-flash-player-windows.html and see if the problem disappears?
    Reinstall both using these installers http://helpx.adobe.com/flash-player/kb/installation-problems-flash-player-windows.html#mai n-pars_text_4

  • How do I create a text box or form field on the top of every page of a pdf in XI Pro for titles?

    I generate pdf content from another program and then in Acrobat XI Pro I want to add titles to each page.
    I'm thinking I can use form fileds and duplicate across all pages but how do I make each form filed unique?
    Or could i add a form field to a background and then apply the background to every page in the pdf?
    thanks.

    This type of thing is probably best done with a script, either by adding a uniquely named field to each page or by spawing a template page that contains just the form field (like your last idea). There's not a built-in method for doing this. If you add a blank page to the beginning of the document, create the field in the location you want, and make the page a template, you can run the following script in the interactive JavaScript console (Ctrl+J):
    // Get a reference to the template
    var t = getTemplate("Field");
    // Spawn the template on each page, automatically renaming the fields
    for (var i = 1; i < numPages; i += 1) {
        t.spawn({nPage: i, bRename: true, bOverlay: true});
    To run the code, select it all in the console and press Ctrl+Enter, or Enter on the numeric keypad.
    To make a page a template in Acrobat 11, make sure you're on the page you want to make a template and select: Tools > Document Processing > Page Templates
    and enter a name. I used a name of "Field" in the example above, but you can use anything.
    To create a blank page, you can use the following script:
    newPage({nPage: 0, nWidth: 8.5 * 72, nHeight: 11 * 72});
    for an 8.5"x11" page. Adjust the numbers to match whatever your page size is. It will be added to the beginning of the document and you can then add the field and make it a template. Once the fields have been added, you can remove the template page.

  • Acrobat X Pro detects no form fields in the PDF created by Excel

    I am using Acrobat X Pro on a Macbook running Yosemite OS X.  Office 2011 and Acrobat are both fully updated.
    I have created a PDF from an Excel spreadsheet.  two columns.  first column has text to describe what the user is supposed to enter in the second column.  the cells in the second column have a border box drawn around them.  I saved this Excel document as a PDF.  I opened it in Acrobat X Pro and used the Tool - Create Fillable Form.  It gives a message saying "No form fields detected".  What am i doing wrong?  Is there an issue with this process?

    i have read at least 4 articles and watch 3 videos that do almost the same process i have explained.  the only difference is that they used Word to create their PDF doc.  they had no issues.
    so i am wondering if there is something wrong with the Excel PDF process.  i have tried this one 2 different MacBooks with same result.
    what does the cell have to have in order for Acrobat to detect it as a form field?
    I have a spreadsheet that has over 300 fields that should have been detected.  so yes, i could create them manually, but i am hoping to get this Acrobat to detect them. 
    I tried the process you did "File=>Create Form".  i got same message.
    i built a separate little test process to describe the issue.  see image that is attached.
    it is very simple, yet no fields were detected.

  • Mapping of Tax Form Fields to the PDF Tax Form

    Hi,
       Can anyone tell me how to see the mapping betw the Tax Form fields and the Tax Form in pdf format. For example in Quarterly State Unemployment form, I have a Tax Form field T003. How can I map this field to a particular field in the Tax Form in pdf format ?
    Thanks And Regards,
    Somdeb Banerjee.

    Hello Somdeb,
    To use the Tax form field say T003 in PDF,  there check box 'Form Processing Indicator' should be checked then only the field is available in PDF to be linked. Detailed documentation on how to use is available in 'Service.sap.com/hrusa'>Year end 2008> Year end reference materials-->' new! SAP ERP 6.0: 2008 U.S Tax Reporting w/ PDF-Based forms '
    With Regards,
    S.Karthik

Maybe you are looking for

  • Looking for a client side JAXP-RPC HandlerChain example

    I would like to add a handler to the client side of a RPC call using 7.0.1. I can't find any examples to follow for this logic in WebLogic or at Sun's site. Does anyone know of some sample code I can browse to? I believe I want to add some files as a

  • What is the best way to get PATHS from one Photoshop psd file to another?

    Hi! New on the site, and I signed up specifically to ask the best way to import one .psd file into another, including the paths on the paths palette. Almost all of my Photoshop drawings make heavy use of vector paths, which I then stroke using using

  • Waveform Not Displaying

    The audio waveform is not displaying on the timeline. I have it turned on with optapplew. I dumped all my waveform cache. It even seems like the source video clips do not have it. How can I tell FCP to redraw all waveform? OR what is the fix? Dual 2.

  • Here's my dilemma.....

    Here's my dilemma.  I have several playlists, some of which contain the same songs.  When I check or uncheck one of those songs in a playlist, iTunes performs the same action in my other playlists.  How do I prevent this?

  • Front panel USB - Where to hook up?

    I've just put together a system using the 845GE Max M/B. I would like to make use of the front panel USB ports on the case, but can't figure where to plug them in. I'm using the USB 2 card, and there's another USB jack on the M/b... Any ideas? Thanks