11 Replies Latest reply on Jul 21, 2008 4:13 PM by (BChase)

    JS Batch Process using dialog box help

      I have a batch process the works great except for one small part.

      I wrote a script that will ask from some input using app.response and use that input for a text Watermark. When I run the batch process it asks me before every file its set to run on. What I want it to do is only ask me once at the beginning of the process and use that input for every file that is processed.

      How can I get it to only ask me once?
        • 1. Re: JS Batch Process using dialog box help
          Level 1
          That's an interesting dilemma. Can you post the JS that you are using? You may be able to set the variable and loop through the rest of the files but no one can say without seeing the code.

          Sabian
          • 2. Re: JS Batch Process using dialog box help
            Level 1
            Here is the code:

            var cResponse = app.response({ cQuestion: "Enter the Month & Year of Published Ad (i.e. August 2008)", cTitle: "Published Ad"});
            if (cResponse == null) app.alert("Process Cancelled");
            else ConvertToPA();

            function ConvertToPA() {

            var size = this.getPageBox("Media"); if ((size[0] == 0) & (size[1] == 612) & (size[2] == 792) & (size[3] == 0))
            { this.addWatermarkFromFile ({bOnTop: true, nHorizAlign: app.constants.align.left , nVertAlign: app.constants.align.bottom , nHorizValue: 184, nVertValue: 12,
            cDIPath: "/Macintosh HD/Users/ben/Desktop/Printer's Final PDF's/Printer's Final (Flyer Stamp).pdf"});
            this.addWatermarkFromText ({cText: cResponse + " Published Ad", cFont: "Arial,Bold", nFontSize: 24, aColor: [ "G", 0.5 ], bOnTop: true,
            nHorizAlign: app.constants.align.center, nHorizValue: 72, nVertAlign: app.constants.align.top, nVertValue: -42}); }; // Flyer Ad Horiz

            var size = this.getPageBox("Media"); if ((size[0] == 0) & (size[1] == 792) & (size[2] == 612) & (size[3] == 0))
            { this.addWatermarkFromFile ({bOnTop: true, nHorizAlign: app.constants.align.left , nVertAlign: app.constants.align.bottom , nHorizValue: 184, nVertValue: 12,
            cDIPath: "/Macintosh HD/Users/ben/Desktop/Printer's Final PDF's/Printer's Final (Flyer Stamp).pdf"});
            this.addWatermarkFromText ({cText: cResponse + " Published Ad", cFont: "Arial,Bold", nFontSize: 24, aColor: [ "G", 0.5 ], bOnTop: true,
            nHorizAlign: app.constants.align.center, nHorizValue: 72, nVertAlign: app.constants.align.top, nVertValue: -42}); }; // Flyer Ad Vert

            };
            • 3. Re: JS Batch Process using dialog box help
              George_Johnson MVP & Adobe Community Professional
              You can set up a global variable to set a flag indicating whether the response prompt has been issued, and only issue it if it hasn't. This might help: http://www.planetpdf.com/developer/article.asp?contentid=6518&ra

              George
              • 4. Re: JS Batch Process using dialog box help
                Level 1
                I think that your right about global variables. I am not really sure how to go about setting that. I have never used global variables before. How would I write that so that it would set the global variable from the response and then use the global variable without asking for the response until all the files were processed? Then I would probably need to delete the global variable?
                • 5. Re: JS Batch Process using dialog box help
                  George_Johnson MVP & Adobe Community Professional
                  That article I linked to shows an example of using a global variable, near the bottom.

                  You could do something like this:

                  if (typeof global.my_flag == "undefined")
                  {
                  // Add your code to get input from user here

                  // Set flag indicating we have input from the user
                  global.my_flag = true;
                  }

                  // Proceed with what you want to do

                  You should also store the input you get from the user (if you get it) into a global variable so it will be available for each document you process.

                  You should also set up a routine to delete any globals you set up once you're done with them, for example:

                  delete global.my_flag;

                  if there's a chance you will run the batch process more than once in an Acrobat session.

                  George
                  • 6. Re: JS Batch Process using dialog box help
                    George_Johnson MVP & Adobe Community Professional
                    Upon re-reading, you don't need a flag, but just need to store the response and test for the presence of the response. Something like:

                    if (typeof global.user_response == "undefined") {

                    var cResponse = app.response({ cQuestion: "Enter the Month & Year of Published Ad (i.e. August 2008)", cTitle: "Published Ad"});

                    if (cResponse == null) {
                    app.alert("Process Cancelled");
                    } else {
                    // Set global variable equal to response
                    global.user_response = cResponse;
                    }
                    }

                    if (global.user_response) ConvertToPA();

                    And when done:

                    delete global.user_response

                    I would suggest doing at least some basic validation of the response to see if it's sufficient to proceed with.

                    George
                    • 7. Re: JS Batch Process using dialog box help
                      Level 1
                      George,

                      Thanks for the reply and the code! I have one question and one problem...

                      First is that it no longer asks me each time for a response which is good however after the first pdf that is processed the the text for the watermark is "undefined". So the first one comes out with what I entered as the response and then the rest come out with the word "undefined" typed out instead of the text that I typed in.

                      Where do I put the delete? Should I include it in the javascript or just put that in the console when I am done? When I put it in the js it asks for a response every time.

                      Thanks for the help so far!
                      • 8. Re: JS Batch Process using dialog box help
                        Patrick Leckey Level 3
                        > Should I include it in the javascript or just put that in the console when I am done?

                        You'll have to manually execute it in the console when the batch process is finished.
                        • 9. Re: JS Batch Process using dialog box help
                          Level 1
                          Ok, thats what I thought.

                          Any ideas on the other thing?
                          • 10. Re: JS Batch Process using dialog box help
                            George_Johnson MVP & Adobe Community Professional
                            In your ConvertToPA function, you need to be using the value of the global variable you set up rather than the value of the variable cResponse. The variable cResponse goes out of scope before the second and subsequent documents are loaded, so you have to get the value you copied to the global variable.

                            George
                            • 11. Re: JS Batch Process using dialog box help
                              Level 1
                              Yeah, I guess I would probably need to do that...

                              Thanks a lot for your help!!!!