5 Replies Latest reply on Dec 3, 2008 3:22 AM by try67

    app.openDoc unpredictable results

    (Kevin_Wiltshire) Level 1
      Hi
      I'm trying to create a simple button that opens a PDF attachment (one of several). I use the following code:

      app.openDoc("my.pdf");

      This worked for one PDF but not others, all of which I have created in the same way. I tried inserting this.disclosed = true in the attachment doc scripts, (and tried app.this.disclosed). But this makes no difference. Strangely, I found that opening the attached file from the Attachments panel, running the PDF optimiser on it as far as saving, and saving the file in a new location then cancelling the optimiser, caused the attached files to load once I returned to the main PDF. However, on saving and closing the main PDF and reopening it, I'm back to square one, but no files open now, not even the original attachment. And now I can't use the optimiser workaround to make the others work. I've tried creating new files from scratch and reading the Acrobat scripting resources, but can find nothing to help me.
      Many thanks
      Kev
        • 1. Re: app.openDoc unpredictable results
          try67 MVP & Adobe Community Professional
          Your file path is very confusing and might mean different things on different computers. What do you mean by "my.pdf"? Is this a file that is located in the same folder all the time? If so, add an absolute path to it. If the location is relative, add a relative reference to the path.
          • 2. Re: app.openDoc unpredictable results
            George_Johnson MVP & Adobe Community Professional
            Use the doc.openDataObject method to open a PDF that is attached to the current document.

            George
            • 3. Re: app.openDoc unpredictable results
              (Kevin_Wiltshire) Level 1
              Hi
              Thanks to both responses.
              The document I'm trying to open is a PDF that is attached to the main PDF so it doesn't have a location - it's embedded.
              I have tried
              this.openDataObject("MyAttachment.pdf")
              doc.openDataObject("MyAttachment.pdf").

              The error for the former is:
              TypeError: Invalid argument type.
              Doc.openDataObject:1:Field Button1:Mouse Up
              ===> Parameter cName.
              The latter just gives:
              doc is not defined
              1:Field:Mouse Up.
              Sorry that these are such basic questions but the JS ref doesn't help at my low level.
              Thanks again
              Kevin
              • 4. Re: app.openDoc unpredictable results
                (Kevin_Wiltshire) Level 1
                Hi
                I think I've solved it.
                This works:
                this.exportDataObject({ cName: "Untitled Object 3", nLaunch: 2 });

                Attachments made via the UI are automatically given the names "Untitled Object"; "Untitled Object 1"; and so on. As long as the attachment list is not re-sorted, these names match the order in the attachment list, which is the order in which the files were attached.

                This script helped me see in the JS debugger what attachment names were in use:
                var d = this.dataObjects;
                for (var i = 0; i < d.length; i++)
                console.println("Data Object[" + i + "]=" + d[i].name);

                However, I'm not sure how to work out which is which if you have multiple attachments that have been re-sorted other than by trial and error.

                Thanks for the help that pointed me to this solution.

                Kevin
                • 5. Re: app.openDoc unpredictable results
                  try67 MVP & Adobe Community Professional
                  (Was just going to suggest that you do exactly that... Good to hear you found it on your own.)