5 Replies Latest reply on Feb 24, 2008 4:51 AM by (Aandi_Inston)

    Newbie can't run code!

      Good day, thanks for your time.

      I'm a newbie JS user; I come from the world of VBA in Excel and am out of my depth!

      I am trying to use some sample code that I found on page 52 of the JavaScript Developer Guide:
      "var filename = this.documentFileName;
      for (var i = 0; i < this.numPages; i++)
      nStart: i,
      cPath : filename + i + ".pdf"

      (I added "filename = this.documentFileName" instead of "filename = "invoice";")

      When I try to run the code in the JavaScript Debugger, I get:
      "syntax error


      I have two questions:
      1) How to fix the code so that it actually saves each page of the .pdf as a new file?


      2) Do I 'run' the JS in the debugger to get desired results, or do I have to save it in a folder somewhere?

      Thank you once again for your help,

        • 1. Re: Newbie can't run code!
          Bernd Alheit Adobe Community Professional & MVP
          What happens when you use the unchanged sample code of the JavaScript Developer Guide?
          • 2. Re: Newbie can't run code!
            Patrick Leckey Level 3
            I'm just mentioning this because of the way you included your sample, I'm not trying to sound like an arse, but you're not running the code with the double-quotes around the whole thing as you have it typed above, are you?

            The documentation does say that the extractPages function is allowed to run in a console event so you shouldn't need to run it as folder-level.

            Bernd's suggestion is a good one, try that too.

            What bothers me is that your error message is saying "Exec" is undefined, but I don't see the text "Exec" anywhere in your code. Where is this coming from?
            • 3. Re: Newbie can't run code!
              (Aandi_Inston) Level 1
              You should also read the section about what "this" actually means, it
              means different things in different cases.

              Aandi Inston
              • 4. Re: Newbie can't run code!
                Level 1
                Thanks PDL for not calling me names! No, I didn't include the quotes when I was trying to run the code. In response to your question "where is this coming from?" I think I have an answer:

                After reading the guides for about 45 more minutes I came to the understanding that if I wanted the code to run, I had to SELECT ALL of it and THEN hit Ctrl+Enter ... who knew :-)

                It works now, great - thanks for your time.

                Aandi - I read up on "this" and I think I'm using it OK, I'll def be back when I have problems though!

                • 5. Re: Newbie can't run code!
                  (Aandi_Inston) Level 1
                  My concern about the use of "this" is that it means something
                  different according to context. For instance in an object method, it
                  is the object to which the method belongs, while in a document level
                  script or field-level script it is the doc object for the current

                  Your code clearly assumes that "this" is a doc object. But to be the
                  case, you must be running in a document level script or field-level
                  script. But you are running in the console. The console is an
                  environment on which the manual is silent, so I don't think it is EVER
                  safe to use "this" in a script typed in the console EVEN IF it may
                  sometimes seem to work.

                  Aandi Inston