Delete Document Level Script Using JavaScript?

Hello all.
Is there a way for a document level script to delete itself? I am running Adobe Acrobat Professional 11.
My situation is that I am currently analysing data using a Java application. The Java application taylors a script to suit each specific PDF, and then inserts it into the PDF automatically. When the PDF is opened, the script runs once and then is no longer needed.
As the script is no longer needed it would be preferred if the script could automatically be deleted. Is it possible the script has access to the field in which it is stored (e.g. doc.javascriptField = "";)? Or by some miracle, a delete function already exists?
I think that due to the lack of need for such a function by general and advanced users I won't get the answer I am hoping for. But it is worth a shot. In the mean time, I am inserting a flag into the KeyWord field so that the script does not run twice. It works, but it is not exactly clean.
Any help would be greatly appreciated.
Thanks
Jonny O

My original idea of...
stamper.addJavaScript("this.addScript("oneTimeScript", "app.alert('Annoying Popup')")");
Did not work.
However, while debugging I did come across the name given to a script added via iText (Java library). The default is "000000000000000". With any added scripts being incremented by 1. So the this.removeScript("ScriptName") function works perfectly.
Thanks
Jonny O

Similar Messages

  • Add application and document level events using javascript

    Hi All,
    I need to do some validation in the preprint event of the pdf document. There are samples available using the UI and adding the script in the script dialog, but my requirement is that i need to map the 'preprint' event and event handler to the pdf document using pure javascript code without the UI. Any help would be greatly helpful. Thanks in advance.
    Regards,
    Charan

    You can write a document-level function into the actions handlers using the doc.setAction() method from a folder-level script, but one folder-level script cannot create another.
    Suppose you have a folder-level function triggered by a menu item, and it has collected a reference to the active document as oDoc:
    var myScript = 'console.println("I am about to be printed and I have " + this.numPages + " pages" );';
    oDoc.setAction("WillPrint",myScript);

  • Document level script to display zeros in calcuated field

    I have created a form, with the calculated fields set to read only, and with a validation script of
    if (event.value == 0) event.value = '';
    (so that the calculated fields do not display as $0.00)
    All but four of the calculated fields are named Item.0, Item.1 etc., plus there are SubTotal, ShippingCharge, CCFee and Total fields that need to stay blank until data is entered into the form.
    Initially, I tried to add the script as a document level script, but it didn't work and I'm thinking it needs more to the script to use at the document level, but I have no idea what more it needs.
    Where did I go wrong?  It certainly would be quicker to add calculated fields if I didn't have to add that validation script to each.

    Even with a document level script you would need to call it in every calculated field.
    I you were to write "app.alert("Hello World");" as a document level function, it would only execute when the PDF was initialized or opened and not again as long as the PDF remained open.
    If you rote a document level function using JavaScript like:
    function Hello() {
    appp.alert"Hello World, I am a function");
    return true;
    It would never run until called  with  a JavaScript statement like "Hello();"
    So even with a document level script and preferably a function, you still would need to edit every calculation to call the function or the script would never run.
    You could also create a document level function to suppress the zero display and then write more code to add the call to this function to the calculated fields.
    You need to learn more about the scope of items, how events are processed within a PDF, what functions are and how to use them effectively. You might want to start with getting or linking to a copy the Acrobat JS API Reference.

  • Document level scripting

    I have read about document level scripting -
    This is a nice feature - since it allows a certain level of generalization rather that writing a scriptlet for each objects events.
    I am using Live cycle designer 8.2
    How can I create a document level javascript function ?  i can't see how to do it .
    I am familiar with java scripting and have been scripting for a number of events but i would really like to be able to have a callable function that I pass certain parmeters to for processing.
    please indicate how I can do this .
    Thanks

    You should post this in the LiveCycle Designer forum here, if you haven't already.

  • Document level scripting from process workflow

    Hi all,
    is there some way to add a "document level" script from process workflow in Livecycle Workbench?
    That is, I have a script i want to add to a pdf in my process workflow. How can I do that? Is there some service/function/script I can use to do that?
    I'd really appreciate any help.
    Thanks
    Alessio

    Not that I am aware of, could be wrong though

  • Move recorded document between scripts using session map

    Hi all experts on scripting!
    We have a 2 scripts ! First script is a callback script that is recording a message from the calling customer which is saved in a"recorded document" that will be played towards an Agent when he/she is picking up the callback call.
    The (Callback) script first records a message from the customer which is saved in a document (not stored in a repository). The Callback script is then doing a "call redirect" to a new script (Agent script) where the agents are answering the callback calls!
    Now we want to move the recorded document/prompt from the "Callback script" in a variable to the "Agent script" so when an Agent is selected he will hear the Callback message from the calling customer and also "receive a voicemail with the recording + CallerID ...in case if the agent doesn't get through to the calling customer!
    Can we úse "get session" and "set session" for this and if so how?
    Rgds Mikael

    Here is a step-by-step of the process to use a Session Object to store and retrieve a Document.
    Script 1
    Variables
    Session the_session = nullDocument the_recording = DOC[]
    Script
    ...You just captured the recording in the variable the_recording.../* Grab a reference to the Session */the_session = Get Contact Info (--Triggering Contact--, Session)/* Store the Document in the Session Object *//* In the properties of this step, you will need go to the Context tab and Add a new context: Name = "the_recording"; Value = the_recording */Set Session Info (the_session)...Now you do your Call Redirect...
    Script 2
    Variables
    Session the_session = nullDocument the_recording = DOC[]
    Script
    ...You have just accepted the call.../* Grab a reference to the Session *//* In a Call Redirect scenario, this is the same Session from Script 1 */the_session = Get Contact Info (--Triggering Contact--, Session)
    /* Retrieve the Document from the Session Object */the_recording = Get Session Info (the_session, "the_recording")/* You now have the Document the_recording in this second script */...Now you are ready to play the recording to the Agent...
    Anthony Holloway
    Please use the star ratings to help drive great content to the top of searches.

  • Document Level Scripts .. Need a simple example!

    I've been trying to add a function to a form just to avoid writing the same script over & over again & am not succeeding :|
    I'm trying to add even only an app.alert function..
    I add a script object under a subform 'P1' called 'hello'..
    in hello, i write
    function hello1
    app.alert("hello")
    you can see the hierarchy here:
    http://i29.photobucket.com/albums/c271/mashdown45/screen.jpg
    in order to call the hello1 function from a button, on the click event, i add the following:
    form1.P1.variables.hello.hello1();
    but am getting an error
    TypeError: form1.P1.variables.hello123 has no properties
    1:XFA:form1[0].P1[0].Button1[0]:click
    (you all must be thinking: 'obviously'.. but i cannot figure it out!)
    Thank you in advance..

    Hi Chris. I created a variable named hello in the hierarchy and typed in:
    function hello1()
    app.alert("hello")
    Then in the click event of the button I put:
    form1.P1.variables.hello.hello1();
    I think all you needed were the "()" after the function name.

  • Using Javascript to reset a form on document load

    I am trying to reset all field vaules on a acrobat form to the default values, when the form is initially loaded.  I am trying to use the resetForm() method in a document level script, but not having any luck.
    I have been able to reset fields after user inputs such as a button that resets the form, or a script the will reset a form prior to importing field data... but I need to ensure all data is removed from the form when the form first loads
    Any ideas?

    I believe you mean a document level JavaScript, Entering Document Level Scripts, since a Folder level script would require the placing of the code into one of the Acrobat Application's JavaScript folder on the user machine, Entering Folder Level Scripts. Placing the JS code as a Document Level Sept will clear the form when the form is opened. One could also use the Page Open action if additional code is added to prevent re clearing the form if part of a multi page document and one navigates back to the original page.
    You should also consider turning off auto complete and auto caching of form data.
    Minimizing Exposure of Personal Information on Public Computers

  • Document Level Header Scripts

    Hello -
    I am looking for any assistance you may have.  I am working on a project in Acrobat Professional 7.0 that requires me to add the computer username to the header of a pdf file.  I have determined, and implemented this in Excel files using an onopen event.  I need to do the same thing but in a pdf file.  I have absolutely no javascripting experience so the more basic your explanation the better.
    After reading up on the internet, I believe that I need a document level script?  I found an example that is:
    this.addwatermarkfromtext({
    ctext: "Confidential Document",
    ntextalign: 2,
    nhorizalign: 2,
    nvertalign: 0,
    nhorizvalue: -72,
    nvertvalue: -72,
    I entered that under Advanced, Javascript, Document Javascript but I receive an error that says typeerror: this.addwatermarkfromtext is not a function.  Again, I would need to change it to pull the username (I am assuming I can do this with a variable?).  I appreciate any and all help.
    Thanks in advance for your time.

    Thanks for the quick response.  Here is my situation.  The pdf file contains highly confidential information.  I want to email it out and have the username automatically appear in the header or footer so everyone is aware of who printed the copy.
    If, according to your last post, cannot assign that to the document level then must that be applied on everyone's computer?  Please note that I am the only one with Professional.  All users will be using the Reader only.
    Thanks again for all of your assistance.  It is greatly appreciated.

  • Document-level Javascript as Object

    I created a document level script called Utility.
    I want to create methods within this script rather than coding each one separately.
    function Utility()
    this.getFormattedDateOnly=function(pDate) {
      if (typeof pDate == "undefined") {
        pDate = new Date();
      var retval = util.printd("m/dd/yyyy",pDate);
      return retval;
    this.getFldsOnPagenum = function(pPageNum, pDoc) {
      /* returns an array of the form fields who are on or start on a page */
      /* zero based return ; however pPageNum is 1 thru numPages, not 0 -> numPages-1 */
      var currPage;
      var currFld;
      var cnt = -1;
      var ARflds = [];
    CPR("# flds=" + pDoc.numFields+" Type of pDoc:"+ (typeof pDoc));
      for (var i = 0; i < pDoc.numFields; i++) {
        currFld = pDoc.getNthFieldName(i);
        if (typeof currFld.page == "number") {
    CPR("page="+(1*currFld.page+1));
          if ((1*currFld.page+1) == pPageNum) {
            cnt++;
            ARflds.length = cnt + 1;
            ARflds[cnt] = currFld;
    CPR("\n cnt="+cnt);
        } else if ((1*currFld.page[0]+1) == pPageNum) {
          cnt++;
          ARflds.length = cnt + 1;
          ARflds[cnt] = currFld;
      return ARflds;
    var MyUtil = new Utility();
    This is all working fine with the following exceptions:
    1) the methods are not being registered in the Javascript hierarchy listing.
    That's annoying.
    2) "This" is not recognized at the document level....I must pass it as a parameter (pDoc).
    I thought that was strange...I could see it if were at the folder level.
    It appears the document object is out-of-scope !!
    3) currFld = pDoc.getNthFieldName(i);
    The above is failing....sending back a "currFld is undefined" error.
    I don't see the problem....very strange IMHO.
    When I call the getNthFieldName function from the console....no problem.
    What am I doing wrong in the definition here ?
    It appears that what I did has Acrobat functions and document properties out-of-scope.

    I think this would work if you could make the document object a member of the Object being created.
    To do that, a constructor needs to be invoked so that it can instantiate a public property of the Object.
    var MyUtil = new Utility(this);
    inside of Utility I would have:
    this.oPDFdoc =  this;
    thereby transferring a reference to the entire PDF document to my Object.
    Getting this to work would eliminate the need for all of the document-level javascript references.

  • How do I validate a certificate (not visible) at the document level?

    I am using Acrobat XI Pro running in Windows 8.
    I created a PDF document with form fields (type: button) and JavaScript codes (field-level and document-level). Before I certify (not visible) and save the document, I want to add a document-level script that checks if the certificate is valid. If the certificate is valid, I would like to  schedule an interval object to update some of the icons in the fields. Is this possible? If so, how do I get the “certificate (not visible) field” and check that it is valid
    Thanks. - john

    I am using Acrobat XI Pro running in Windows 8.
    I created a PDF document with form fields (type: button) and JavaScript codes (field-level and document-level). Before I certify (not visible) and save the document, I want to add a document-level script that checks if the certificate is valid. If the certificate is valid, I would like to  schedule an interval object to update some of the icons in the fields. Is this possible? If so, how do I get the “certificate (not visible) field” and check that it is valid
    Thanks. - john

  • Jump to a specific bookmark using JavaScript

    Hello,
    I am able to successfully jump to a specific bookmark in a PDF document when I run the following code in the Debugging Console:
    // Jump to "Monthly Summary"
    for (var i=0; i<this.bookmarkRoot.children.length; i++) {
                if (this.bookmarkRoot.children[i].name.indexOf("Monthly Summary")!=-1) {
                   this.bookmarkRoot.children[i].execute();
    The problem is that I would like to be able to run this code in a folder level JavaScript file ,however, the above code does not work for me.
    What must I change to make this code work in an external JavaScript file?
    Any help would be appreciated.
    Thanks
    Linda

    Since a bookmark only exist as an object in a PDF file how can it work as written as a folder level script without any control. All folder level scripts are run when the Acrobat/Reader application is started and possibly before any PDF file is opened. So your code will run but not find any bookmarks.
    Have you tired to run this code when there is no open PDF file?
    I get the following error when there is no open PDF:
    this.bookmarkRoot is undefined
    3:Console:Exec
    TypeError: this.bookmarkRoot is undefined
    3:Console:Exec
    undefined
    The "undefined" means there is no bookmarkRoot defined or found. Note bookmarks only exist within a PDF file that have bookmarks.
    Next, once you get a PDF open, how are you going to get this code to run for the form when there is no way to identify the block of code to run?
    As George has suggested you need to create/define a function and then call that defined function form within the PDF. Once a function is defined, that function can be called by the name of the function as part of the document level function for a PDF form, or as a field or bookmark action.
    Since you have decided to place this code in the user's Acrobat JavaScript folder, how are other users going to call this code located on your system. Using your approach will require all users need to install your code on their system. If you were to put the code in the PDF as a document level script, the script it could execute upon opening the PDF. If one put it in as a document level function, then it could be called upon opening the PDF, as a bookmark, as a button, etc.
    I would look for a function to open any bookmark in the PDF by bookmark name by searching for the existence of that named bookmark. With this approach, I could use the function in any PDF and execute any possible bookmark as needed.

  • Document-level javascript quandry

    Ok, completely clueless newbie here whose only coding experience is Access VBA…from a few years ago. Need to write up some Javascript to make this work – that was a month’s worth of a migraine.  I ask for your patience, and would like to ask for forgiveness in advance for any headaches I induce while you try to figure out my problem(s).  Also, I’m not sure how to copy paste images or code examples, but I will do my best.
    So, basic premise:  make a drop-down combo box that will populate another combo box based on whatever was selected in the first box – in this case, 31 items in the ‘Inventory Parts Used’ list, and a total of 427 respective sizes in the other list. 
    YES, I’ve already looked at that http://acrobatusers.com/tutorials/js_list_combo_livecycle1 example, and followed it closely.  Took me forever, but I somehow got it to work. Was very happy.  Only thing I couldn’t figure out was the export value b/c mine wasn’t a number.  But I solved that by putting the CodeID and respective PartSize together (ex: 4-inch Fire Hydrant would show up as "FH-01:  4"). Anyways, I selected that working row and choose the “Place Multiple Fields” option times 15 rows.  Still working.  I’m dancing a jig. Then I tried to check on the code: 
    “Text cannot be displayed in full by the Edit Dialog.  Please use an External Editor.” 
    Uh… So I deleted a row at a time until I could see what my limit was.  I had to pare down 15 rows to a measly 3 rows.  Took me a while but I was able to see where the problem was.  Instead of being written into the Document-Level JS, my array was tied to the first combo box’s Keystroke event on the Field Level.  So when I multiplied the rows, that humongous list essentially had diarrhea.
    I’ve tried to delete that header and keep it to Document Level.   It basically ignored me and keep those lines.  When I did manage to make the <Document-Level> on top, it just didn’t work.
    (    //<AcroForm>
    //<ACRO_source>Row0.InvPart:Keystroke</ACRO_source>
    //<ACRO_script>
    /*********** belongs to: AcroForm:Row0.InvPart:Keystroke ***********/    )
    I’ve searched other forums about the Document-level…. I swear I read a lot of forums that said using Advanced>Document Processing>Set Document Actions>Edit All was ok. Clearly it’s not ok, especially after I found this forum: http://answers.acrobatusers.com/Where-I-enter-document-level-javascript-adding-FormRouter- Calendar-q55527.aspx. 
    So I guess my question(s) is this:  IS that “Edit Document Javascripts” really necessary?  B/c I’ve looked and I don’t have it. I’m using Adobe Acrobat 9 Standard, ver 9.5.5 (and I’m using Windows XP Pro ver 2002 , if that matters).  Is this JS editor only available to the Pro version?  Would it really be a bad thing to just leave it alone as a keystroke event (aside from the unwieldy large, duplicated codes it vomits as a result)? Or maybe, is there a way to code a new row on instead?  I remember seeing an example where you can add more lines as needed, but I can’t for the life of me find it again.
    Thank you in advance for all your assistance.

    * Huh....it just figures... right after I finally give up and post up a question, I would find the answer. =_=;; http://forums.adobe.com/message/4727325#4727325. 
    So, Standard version apparently doesn't have that exalted “Edit Document Javascripts”.  Apparently a way around it is using the Page Open event.  Well, it works - the massive array only shows up once in the editor, and the multiple rows each call the function instead.  Nice. 
    Well, I will leave this up in case someone else can use the reference.  Thanks to anyone who read this and was going to answer me. =)
    Don't suppose anyone knows how to create a code to add new rows instead of having 15 rows straight off the bat?  Or should I make a new post for that?

  • Document Level Javascript

    Is it possible to create document level javascript ?
    I would like to create a function that I would be able to call in events.
    And is it possible to store an object (like an ADBC connection) at the document level to access it where I want ?
    Thanks.
    Laurent

    There is something called "script object". The script object is an object that you can use to store JavaScript functions and values separately from any particular form object. Typically you use the script object to create custom functions and methods that you want to use as part of scripts in many locations on your form. This technique reduce the overall amount of scripting required to perform repetitive actions.
    To add a new script object to your form:
    - Create a new form or open an existing form.
    - In the Hierarchy palette, right-click either a form-level object or a subform-level object and select Insert Script Object.
    - You can rename your script object (optional) by right-click the script object and select Rename Object.

  • Getting errors while updating links in Indesign document using javascript

    Hi,
    We are updating the links in InDesign document using javascript. After running the script, we are getting the below errors in Adobe InDesign CC debug.
    When closing the document for first time we are getting the below mentioned errors,
    ASSERT 'fRefCount == 0' in c:\development\citius\source\components\database3\revisioneddatabase\SaLRICache.tpp at line 230 failed.
    Erased item list not empty at block delete time
    blockUID = 10486786 not freed
    Internal error: 904 items were leaked!
    After that we are opening the same document for second time, then we are getting the below mentioned errors,
    ASSERT 'ts_DBPubFile->PlacementUIDIsAvailable(uid)' in c:\development\citius\source\components\database3\revisioneddatabase\SaLRIUtils.tpp at line 195 failed.
    DB failed to create UID!
    ASSERT 'this->FindInIDRangeList(fLastCreatedBlockUID) >= 0' in c:\development\citius\source\components\database3\revisioneddatabase\SaLRICache.tpp at line 476 failed.
    ASSERT 'fLastCreatedBlockUID != kInvalidUID && fLastCreatedItemID != 0' in c:\development\citius\source\components\database3\revisioneddatabase\SaLRICache.tpp at line 467 failed.
    ASSERT '(SaLRIUtils<SnapshotID , SnapshotInfo>::ts_DB)->IsValidUID(itemUID)' in ..\..\..\source\components\database3\revisioneddatabase\SnapshotCache.cpp at line 55 failed.
    Please help us to solve this error in InDesign debug.
    Thanks,
    Vimala L

    You're probably better off raising this in the SDK forum.

Maybe you are looking for

  • Can u/how do u  share playlists between different apple accounts on the same computer?

    My other half has own iphone    how do I share i tunes with 2 different phones and 2 itunes ids

  • PI inbound proxy

    Dear All, We are planning build one proxy to recieve the file from thirdy party to SAP though PI system . So I have couple of questions in this regard. 1)  How is this proxy in ABAP side trigger to run ? Do we need to schedule any background job run

  • SAP BUSINESS ONE FOR RENTAL BUSINESS

    Hi, Is there any option available to map a rental business process in standard SAP business one without any customizations. Regards, Vinoth Florian.Z

  • Internet sharing, do we have to pay for it?

    Do we have to pay AT&T for it to make it work? Is it like a service? Solved! Go to Solution.

  • How to rotate 2 3D paths?

    Hi, I have A.I CS6 i was wondering if two different shapes could rotate using the same center of z-axis rotation.. It ended that the only way to do it is that both objects have to share the same extruded properties.... If i create both objects with i