5 Replies Latest reply on Nov 25, 2014 9:44 AM by try67

    Why is Doc.closeDoc causing memory reference error?

    hopgal Level 1

      My script worked fine when I tested it with Adobe Pro.  It is only in Adobe Reader X that it crashes and closes the app.

       

      In LiveCycle ES version 8.2, I added JavaScript to do the following in the preSubmit event of a hidden Submit button:

       

      var currentDoc = event.target;

      var path = currentDoc.path;

      execMenuItem("SaveAs",currentDoc);

      var newPath = currentDoc.path;

      if (path != newPath){

           //re-open the original document (blank form)

           app.openDoc({cPath:path});

      }

      //stop the submit event

      xfa.event.cancelAction = true;

      //close the current document (completed form)

      if (currentDoc.disclosed = true){

         currentDoc.closeDoc();

      }

       

      From the JavaScript API documentation, I learned that the document has to have the disclosed property set to true to be available to other open documents.  I am doing this by calling a document-level function in the form1.docReady event, which I have verified is running when the document opens.  The original document is being opened, the saved document is being closed, but when the "Submit Cancelled" dialog box appears and I click "OK", I get this error:

       

      The instruction at "0xsomething" references memory at "0x00000010".  The instruction could not be "read".

       

      And whether I hit "Cancel" or "OK", the reader closes.  If I comment out the cancelAction, the same thing happens, only without the Submit Cancelled dialog.  So it must be the Doc.closeDoc that is doing it.  I have also tried putting the code in the postSubmit and setting a timeout, but in those cases the close never happened at all. 

        • 1. Re: Why is Doc.closeDoc causing memory reference error?
          gkaiseril MVP & Adobe Community Professional

          Have you checked the Acrobat JS API Reference?

           

          Reader does not have all the same rights or methods available to Acrobat.

           

          If the PDF has been changed and you try to save the PDF will have to save rights. This is not normally amiable to Reader. You have to add special rights to the PDF with Acrobat.

          • 2. Re: Why is Doc.closeDoc causing memory reference error?
            George_Johnson MVP & Adobe Community Professional

            The following line:

             

            if (currentDoc.disclosed = true){

             

             

            Should be changed to:

             

            if (currentDoc.disclosed == true){

             

             

            Which is the same as:

             

            if (currentDoc.disclosed) {

            • 3. Re: Why is Doc.closeDoc causing memory reference error?
              hopgal Level 1

              My actual code does have == , not = .  I would have cut and pasted the snippet in here, but it seems that is not allowed.  But thanks for replying!

              • 4. Re: Why is Doc.closeDoc causing memory reference error?
                hopgal Level 1

                Yes, I have read the JavaScript API.  That is how I found out about the "disclosed" property.  If it were a security or permissions issue, I normally find those while debugging in Acrobat Pro, in the JavaScript console.

                 

                I know there are some things you can't do in Reader that you can do in Pro, but it doesn't make sense to me that closing a document should be one of them.   If so, why even have the closeDoc method?

                 

                It seems like the document is closing before some other task can finish.  I also tried setting a timeout on it, but then it doesn't close at all. 

                 

                app.setTimeOut(currentDoc.closeDoc(),5000);

                 

                One reason we have to close these documents is that after calling xfa.event.cancelAction = true, none of the select boxes or buttons work anymore.  It is unclear where to set this back to "false".  I tried setting it in the preOpen events of the select lists, but it had no effect.  It can only be called in preSubmit, preOpen, preSign, preSave.  So, I decided it would be better just to close the document.  When they reopen it, everything works again.

                • 5. Re: Why is Doc.closeDoc causing memory reference error?
                  try67 MVP & Adobe Community Professional

                  I encountered a similar problem with Reader XI crashing on closeDoc so I took the advice from your reply (to use a time out) and it worked. However, the code above is incorrect. It needs to be something like this for it to work:

                   

                  var a = app.setTimeOut("currentDoc.closeDoc();",5000);

                   

                  Hopefully this will help others with similar issues in the future.