20 Replies Latest reply on Jun 17, 2010 11:54 AM by gkaiseril

    please help with Javascript obejcts hierarchy

    Grigorianus

      Hi!
      Is following Javascript obejcts hierarchy is right?

       

      1. App > 2. Doc > 3. Page >

      (from Page) > 3.1 Annotation3D
      (from Page) > 3.2 Field (link)

       

      thank u )

        • 1. Re: please help with Javascript obejcts hierarchy
          try67 MVP & Adobe Community Professional

          What do you mean, exactly?

          The Document object is not a property of the App object. The two exist separately, although obviously there can't be a Document object if there isn't an application open. Also, there's no such thing as a Page object in Acrobat JavaScript.

          • 2. Re: please help with Javascript obejcts hierarchy
            gkaiseril MVP & Adobe Community Professional

            Are you talking about the initialization of Acrobat when you double click on a PDF?

             

            If so, you should test your version as I have seen some document level scripts fire before an application folder script. But I have not researched why this happens. If it is important for one script to fire before another, you can use flag variables or other coding checks to see if a script has run or created an object and if not then set a timer action and test for the existence again or provide some other action to test for the successful action later in your processing. I have used the 'type of' statement to test for a given user created application folder function, each time that function needs to be called.

            • 3. Re: please help with Javascript obejcts hierarchy
              Grigorianus Level 1

              I need this informations as a part for my article (whitepapper).

              I look for how app, doc, page, field and annot3d (no matter they are objects or properties of one another) are correlate one with anoter (or its hierarchy)

               

              1. If Doc is not a part of App, why we open Doc using App object (see Acrobat SDK: JavaScript for Acrobat API Reference > JavaScript API > Doc):

              var myDoc = app.openDoc("myNovel.pdf", this);

              or Doc is property of App object?

               

              2. Page is property of Doc object?

              • 5. Re: please help with Javascript obejcts hierarchy
                Grigorianus Level 1

                I has read it before. But I can't find there answer to my question

                Please look at this picture:

                http://livedocs.adobe.com/acrobat_sdk/9.1/Acrobat9_1_HTMLHelp/images/JS_Dev_Overview.71.7. 1.jpg

                Feld and Annotation (3D annotation is part of Annotation) is part of Doc object.

                May be Doc and App is separate objects, but one can open documents using App objects.

                • 7. Re: please help with Javascript obejcts hierarchy
                  Grigorianus Level 1

                  What is True?

                   

                  So to access to some type of annotation (link, 3d) we must

                  1. access to App for open some file

                  2. access to Doc (or this)

                  3. access to Page (current or PageNum)

                  4. access to link (create, delete)

                  ?

                  • 8. Re: please help with Javascript obejcts hierarchy
                    gkaiseril MVP & Adobe Community Professional

                    You have to have Acrobat/Reader open to open a PDF and use some or all of the Acrobat JS features.

                     

                    When Acrobat/Reader is started various folders are accessed and files within those folders read and processed to create the application. This includes dictionaries, certain global variables, various functions provided by Adobe, and user defined functions or variables. The Adobe provided functions or user provided functions or variables are accessed by their assigned name. So if you created an application folder level function in a file called 'hello.js' containing the following code:

                     

                    function HelloWorld()

                    {

                    app.alert('Hello World!');

                    return;

                    }

                    HelloWorld();

                     

                    Each time you open Acrobat an alert box with "Hello World!" will appear.  So even without any PDF open one can perform or have a task done. With application level scripts, you can add menu item, tool bar buttons, or modify menu items, etc. So when you open Acrobat you could have a menu item to create a new blank PDF or add the JS API Reference to the "Help" menu item. And if you selected "Help => JavaScript API', the JS API Reference file would open, whether there is an open PDF or not.

                     

                    PDF files are opened at the application level, as the application needs to interpret the code of the PDF file and provide the necessary resources for displaying, calculating, linking, etc for the open PDFs. If you open a PDF pragmatically, you need to provide an object name to that PDF. Especially if you are going to reference that file with JavaScript.

                     

                    Within an open PDF there are various actions. The first is the document level scripts that are used to establish the environment in which that PDF will function. This could include special functions to sum values, compute date differences, perform special key stroke and formatting. There can even be test to see if there are any necessary application level functions available for use the the document.

                     

                    Within PDF document you can can fields, links, comments, etc. And these items only exist in the PDF document and rely on the PDF document for performing the various task or communicating those task the the application.

                     

                    By the way with the "HelloWorld" function defined in the application JavaScirpt folder, and PDF opened on that computer can have a button with the 'mouse up' action JavaScript of "HelloWorld();" for the code and any time that button is pressed the alert box that appeared when Acrobat was started will appear. But if you take that PDF to another computer that does not have that file nothing will happen or an error box will appear.

                     

                    See Getting Started - Developing for PDF by Dave Wright and look around the Planet PDF site.

                     

                    You also need to realize that Acrobat JavaScript does not run synchronously, so you do not always have the individual scripts running in the same order or speed so it is possible a script will not always start and end before the next script in line is started or ends. And if you have dependencies between these scripts you need to test to see if they are all met.

                    • 9. Re: please help with Javascript obejcts hierarchy
                      Grigorianus Level 1

                      GKaiseril, thank you, but it is not direct answer to my question

                      I only need relation between App, Doc, Page, Link, Annot3D objects.

                      If you need create link, you have to open document using App, then get page using Doc, then creater or delete Link.

                      • 10. Re: please help with Javascript obejcts hierarchy
                        Vaibhav Padlikar Level 2

                        In terms of Hierarchy, it will be better to correlate the JS applied at various levels. Consider JS applied at App level , Doc level , Page level , Field level etc.

                         

                         

                         

                        Hierarchy wise App level scripts will execute first, and then Doc > Page > Field.

                         

                         

                         

                        As far as comparing the objects, hierarchy would hold good if the objects lower in hierarchy are derived from parent objects, which is not the case here. It is true that there are ways in which Doc object is returned using app.openDoc or app.activeDocs but there are other ways to access Doc object such as event.target and that does'nt mean that event.target is up in hierarchy to Doc.

                         

                         

                         

                        It would help if you can share in what context / usecase you are writing this for. Perhaps, I misunderstood the question. This is to best of my knowledge.

                         

                         

                         

                        My 2 cents.

                         

                         

                         

                        -vaibhav

                        • 11. Re: please help with Javascript objects hierarchy
                          gkaiseril MVP & Adobe Community Professional

                          But the exact order of execution upon initializing Acrobat/Reader will depend upon where exactly the script is located, the order in which folders and  files within folders are loaded, the order of functions within a file, and the order in which Acrobat/Reader applies document level scripts and page open scripts.

                           

                          I have seen different versions of Acrobat run the page open action before a document level function when one double clicks a PDF file icon.

                           

                          Functions and objects also have a scope over which they are active, a document level function in one document is only available to that PDF and not another PDF. One can even override an application level script by creating a function with the same name within a PDF, an example of scope.. There is an exception that is caused by the 'global' object that one can use to create a memory resident object or automatically shared field that is available to any open PDF and then for the 'global' object there are the 'setPersistent' and 'subscribe' methods that modify the availability across sessions or files.

                           

                          You can check the order by adding scripts to various locations and straiting Acrobat/Reader and opening a PDF.

                           

                          In general:

                           

                          Application Initialization:

                          Application JavaScripts folder - files in ASCII sorted order then by line of code

                          User application JavaScript folder - files in ASCII sorted order then by line of code

                           

                          Opening a PDF:

                          Document level script - in ASCII sorted order of scripts then by line

                          Open Page action - by oder in which added then by line N.B. Sometimes this will fire before documentlevel depending upon version.

                          Form fields - in form field calculation order. Calls start from form field, document, application for first occurrence of function.

                          • 12. Re: please help with Javascript obejcts hierarchy
                            Vaibhav Padlikar Level 2

                            That's true. Rightly explained.

                             

                            -vaibhav

                            • 13. Re: please help with Javascript objects hierarchy
                              Grigorianus Level 1

                              I don't ask about difference of scripts thats located in folders or saved inside of PDF

                              • 14. Re: please help with Javascript obejcts hierarchy
                                Vaibhav Padlikar Level 2

                                As I said previously, it would help if you can share some background / context regarding your question pertaining to object hierarchy.

                                 

                                 

                                 

                                -vaibhav

                                • 15. Re: please help with Javascript obejcts hierarchy
                                  Grigorianus Level 1

                                  I don't know how explain this more exactly.

                                  But I try in other way:

                                  how we can access to objects

                                  1. Doc object (example: app.openDoc)

                                  2. Page object

                                  3. Annotation object

                                  4. Link

                                  5. 3d artwork (3d annotation).

                                  I try to make graph that shows these objects (also App object) correlations.

                                  thank

                                  • 17. Re: please help with Javascript obejcts hierarchy
                                    Grigorianus Level 1

                                    its ok, but App object not present there.

                                    Or it is no good to show how Doc and App objects are relating?

                                    • 18. Re: please help with Javascript obejcts hierarchy
                                      try67 MVP & Adobe Community Professional

                                      You can add app above doc, if you want.

                                      • 19. Re: please help with Javascript obejcts hierarchy
                                        Grigorianus Level 1

                                        > You can add app above doc, if you want.

                                        I will if it's will be right

                                        • 20. Re: please help with Javascript objects hierarchy
                                          gkaiseril MVP & Adobe Community Professional

                                          You might want to look at Acrobat JavaScript Scripting Guide and within the JS API Reference look at the 'event' object's section about Form Event Processing.

                                           

                                          You also have the JS engine on the system that provides objects like Array, Date, Math, Function, etc.