Professional Web Applications Themes

Where to put Javascript StartUp scripts? - Adobe Acrobat Windows

I thought I knew JavaScript and I thought I knew Acrobat but I am still conceptually spazzed frequently, when I try and figure where certain scripts should live in a PDF. I am trying to place a startup/initializing script in my PDF project. And I am not quite sure where it should be located so that it can be triggered by the opening of the doc. It needs to happen before anything else executes. So I thought, according to doentation, that this script should go in the Doent Level Scripts. I can't have any folder scripts because this project has ...

  1. #1

    Default Where to put Javascript StartUp scripts?

    I thought I knew JavaScript and I thought I knew Acrobat but I am still conceptually spazzed frequently, when I try and figure where certain scripts should live in a PDF.

    I am trying to place a startup/initializing script in my PDF project. And I am not quite sure where it should be located so that it can be triggered by the opening of the doc. It needs to happen before anything else executes. So I thought, according to doentation, that this script should go in the Doent Level Scripts.

    I can't have any folder scripts because this project has to stand and live on its own, with the exception of Adobe Reader 6 or Acrobat 6 to run it. All script control must live in the doc.

    I have the code itself figured out but the placement and trigger location has got me stumped. I had planned to trigger the script with an Event Object, event type Doc/Open. This would be targeted at my doc to avoid other Doc/Opens from triggering it. There is a mirror script that reverses the startup script's behavior on the event trigger Doc/WillClose.

    I get that doent wide scripts need to be at the doc level so that they can affect and be accessed from the whole project but do all scripts at the doent level have to be named functions? Can you have scripts at the doent level that are unnamed statements? Is this what Adobe means, on page 208 of the Acrobat JavaScript Scripting Reference , when they say,

    "When a doent is opened, the doent level script functions are scanned
    and any exposed scripts are executed."




    What are exposed scripts?

    I know I need to put my getUserPrefState at the doent level but where do I put the event trigger? Since getUserPrefState needs to be triggered by the outside call doc.open where does that go? The Doent Level Script Dialog Box seems to require named functions.

    I have seen in some other people's projects that have put these kind of scripts at the page level, on the first page and trigger it with a page.open. This is impractical for a doc that needs its first page and it can be a rough visual opening for the user since the dependent setup takes place after the first page is already visible.

    I am at a loss in understanding a lot of Acrobat's internal message passing scheme. I get the feeling that I am missing something really obvious.

    So would someone please illuminate this poor soul to what is probably right in front of my face?
    Garrett_Cobarr@adobeforums.com Guest

  2. #2

    Default Re: Where to put Javascript StartUp scripts?

    When you create a doent-level JavaScript, it provides you a function skeleton by default. You can place code within one or more function definitions, or outside of a function definition. Code that is outside of a function definition is executed when the doent open, which is what you want. Functions are read into memory and are available to be called by code. Be aware that the order of loading doent-level JavaScripts is undefined. This means that if you have code that depends on other code (another function, for example, be sure to place it physically after the code it depends on.

    George
    George_Johnson@adobeforums.com Guest

  3. #3

    Default Re: Where to put Javascript StartUp scripts?

    Thanks George, that straightens me out.

    I find the Acrobat interface confusing with so many different JavaScript windows. They need to bring it all into one, clearly labeled, JavaScript editor-debugger. Access to objects and widget's, pages, doc, and app scripts should be in one structured window so that you can see their relationship with one another and be able to get at their scripts from one window.

    "Code that is outside of a function definition is executed when the doent
    open,"




    Is that what the phrase exposed scripts means?

    We're you saying in the end of your response that the doent scripts are read into memory in the order they appear from the top to the bottom of the doent level script window?

    And thanks, again.
    Garrett_Cobarr@adobeforums.com Guest

  4. #4

    Default Re: Where to put Javascript StartUp scripts?



    We're you saying in the end of your response that the doent scripts
    are read into memory in the order they appear from the top to the bottom
    of the doent level script window?




    I was trying to avoid saying that, since Adobe has never officially said that. It turns out that they are loaded in alphabetical order (in every JavaScript-capable version of Acrobat so far), but I suppose it could change in the future, so don't depend on it.

    Is that what the phrase exposed scripts means?




    Maybe. I'm not aware of that being a common or precise term.

    George
    George_Johnson@adobeforums.com Guest

  5. #5

    Default Re: Where to put Javascript StartUp scripts?

    I would not have guessed alphabetical.

    So that means un-named scrips are dealt with the order it is encountered and then the named functions in order of alphabet?
    Garrett_Cobarr@adobeforums.com Guest

  6. #6

    Default Re: Where to put Javascript StartUp scripts?

    No, I didn't say that functions are loaded in alphabetical order. Rather, doent-level JavaScripts are loaded in alphabetical order. A doent-level JavaScript can have zero or more functions and zero or more lines of code outside of functions. As each doent-level JavaScript is loaded, the code is dealt with in the order it is encountered.

    George
    George_Johnson@adobeforums.com Guest

Similar Threads

  1. Include javascript in a javascript file
    By pentool in forum Macromedia Dynamic HTML
    Replies: 1
    Last Post: October 28th, 02:55 PM
  2. CS: Scripts do not appear in Scripts menu
    By jlw99@adobeforums.com in forum Adobe Illustrator Macintosh
    Replies: 3
    Last Post: May 18th, 04:49 PM
  3. PS CS - Javascript Error on Scripts > Layer Comps to PDF?
    By Mike_Boreham@adobeforums.com in forum Adobe Photoshop Mac CS, CS2 & CS3
    Replies: 2
    Last Post: April 14th, 05:53 PM
  4. need javascript staff (anyone who knows javascript peroid) (READ)
    By Šark Templer webforumsuser@macromedia.com in forum Macromedia Dynamic HTML
    Replies: 14
    Last Post: January 9th, 01:37 PM
  5. scripts that control other scripts
    By kiaoraFiona webforumsuser@macromedia.com in forum Macromedia Director Lingo
    Replies: 8
    Last Post: October 6th, 05:07 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139