10 Replies Latest reply on Apr 11, 2009 9:30 AM by Jim MacD

    Code to Close An Open Document

    Jim MacD Level 1

      What would be the code in the following Javascript, to close the pdf document? I'm trying to open a document (which I can do), read from it, then close it (which I haven't been able to do). Is it possible to open the document, keeping it hidden, read from it and then close it?

       

      I'm using adobe pro 8.

       

       

      ==============================================================================

       

      {

       

       

      var otherDoc = app.openDoc("myDoc.pdf");     <----------- this opens the document, but I'd like it to stay hidden, is it possible?

       

      [Code to close myDoc.pdf ???????]                   <------------ code to close the document ????    

       

       

       

      }

        • 1. Re: Code to Close An Open Document
          MarkWalsh Level 4

          otherDoc.closeDoc()

           

          If you want to close it without prompting to save it, then

           

          otherDoc.closeDoc(true)

          • 2. Re: Code to Close An Open Document
            Patrick Leckey Level 3

            You will have to make sure that the document you load via openDoc is setting it's disclosed property to true or you will not be able to call closeDoc (or any other methods) from that document - in fact, your "otherDoc" variable will remain null unless the document discloses itself.

            • 3. Re: Code to Close An Open Document
              Jim MacD Level 1

              Still didn't work.

               

              I’m trying to open a document using Javascript, keep it from being viewed, read from it, then close the document. The code below should open a document, then close it. It opens the document, but does not close it. Instead it generates the error message below. I’m using Adobe pro 8. command?

              ------------------------------------------------------------------------------------

              {

               

              var otherDoc = app.openDoc("Setup.pdf");    ß This works and opens the document

               

              otherDoc.closeDoc(true);                                ß This doesn’t work and document remains open

               

              }

              --------------------------------------------------------------------------------------

               

              Acrobat JavaScript Debugger Functions Version 7.0

              Acrobat Database Connectivity Built-in Functions Version 8.0

              Acrobat EScript Built-in Functions Version 8.0

              Acrobat Annotations / Collaboration Built-in Functions Version 8.0

              Acrobat Annotations / Collaboration Built-in Wizard Functions Version 8.0

              Acrobat Multimedia Version 8.0

              Acrobat SOAP 8.0

               

              otherDoc has no properties

              5:Field:Mouse UpException in line 5 of function top_level, script Field:Mouse Up

               

              otherDoc has no properties

              5:Field:Mouse Up

              otherDoc has no properties

              5:Field:Mouse UpException in line 5 of function top_level, script Field:Mouse Up

               

              otherDoc has no properties

              5:Field:Mouse Up

              • 4. Re: Code to Close An Open Document
                Bernd Alheit Adobe Community Professional & MVP

                Did you set the disclosed property of  Setup.pdf to true?

                • 5. Re: Code to Close An Open Document
                  Jim MacD Level 1

                  How do I set the "Setup.pdf" disclosed property to true? I read up on 'disclosed property' after your reply, but don't understand it. Currently, the "Setup.pdf" document opens, but doesn't close with the code I use.

                  • 6. Re: Code to Close An Open Document
                    MarkWalsh Level 4

                    In your  "Setup.pdf" file, you need to run this:

                     

                    this.disclosed = true;

                     

                    You cannot run this from a separate file. the PDF that you want to control needs to run the script itself.

                    • 7. Re: Code to Close An Open Document
                      Jim MacD Level 1

                      Hmm ... still can't run it. I've attached two pdf documents. The first "Blank-Doc.pdf" is used to open and close "Setup.pdf". Both are quick sample pdf documents I created for testing opening and closing a pdf document.

                       

                      If anyone would like to take a crack at the code to open and close "Setup.pdf", I'd be thankful.

                      • 8. Re: Code to Close An Open Document
                        Bernd Alheit Adobe Community Professional & MVP

                        The property disclosed of document Setup.pdf is false.

                        • 9. Re: Code to Close An Open Document
                          MarkWalsh Level 4

                          You haven't added the code to the 'Setup' pdf.

                           

                          In that file, change your switchBackground script (or add another document script with the first line) to:

                           

                           

                           

                           

                          this.disclosed = true

                           

                          function switchBackground(fieldName)

                          {

                          if (getField(fieldName).fillColor == "T")

                          {

                          this.getField(fieldName).fillColor = color.yellow;

                          }

                          else

                          {

                          this.getField(fieldName).fillColor = color.transparent;

                          }

                          }

                           

                           

                           

                           

                          Plus, if you want to close the Setup doc, you need to change the button code in your blank doc to

                           

                           

                          {

                           

                          var otherDoc = app.openDoc("Setup.pdf", this);

                          // Don't know what you want to do with the Setup doc, but do it here.

                          otherDoc.closeDoc(false);

                           

                          }

                          • 10. Re: Code to Close An Open Document
                            Jim MacD Level 1

                            Finally - it works. Thank you very much.