1 Reply Latest reply on Dec 21, 2013 3:42 AM by try67

    Building a dynamic dialog in Acrobat with Javascript

    JADarnell Level 1

      I am attempting to figure out how to build dynamic dialogs within Acrobat using Javascript.

       

      I am attempting to write a generalized PDF page splitter.  The user selects a PDF document, and then the script analyzes the open document and determines that there are N pages in the document.  I am going to run through the document and make each page its own PDF.  Each page will be considered a certain kind of page, for example, Cover, Article, Ad, etc.  and the type of page it is will affect the naming convention I use when making the new, one-page file.  For example, let's say that pages 36, 37 and 38 are page, ad and article, respectively.  Then the names I will be using for each output file will be as follows:

       

      P12345Pg_036.pdf

      P12345Ad_037.pdf

      P12345Ar_038.pdf

       

      But there is no way for my code to actually look at a given page and decide that it is page, article, ad, or one of four cover types, etc.  So I want to build a dialog that looks something like this (assume a O is meant to be a radio button):

       

      Page          Pagetype

      1                  O Page      O Inner cover Front         O  Outer cover Front     O Ad           O   Article

      2              O Page  O Inner cover Front     O  Outer cover Front O Ad       O   Article
      3              O Page  O Inner cover Front     O  Outer cover Front O Ad       O   Article
      4              O Page  O Inner cover Front     O  Outer cover Front O Ad       O   Article

      ...

      N              O Page  O Inner cover Front     O  Outer cover Front O Ad       O   Article

       

      Beacuse each document varies in length, that means the dialog will need to be dynamic.

       

      I have looked at the Acrobat API and determined that defining a dialog looks something like this:

      var DialogABC = {

                                         initialize: function(dialog){},

                                         commit : function(dialog){},

                                         ...

                                         description:{}

                                 };

       

      app.execDialog(DialogABC)

       

      What I do not know how to do is create the dialog specification on the fly.  Do I treat it as a string or is there some other way of making this happen?  How can I make a dynamic description that allows for a variable number of rows?

       

      Please let me know if you have any thoughts.  A good reference or example would serve just as well.

       

      TIA!

      John

        • 1. Re: Building a dynamic dialog in Acrobat with Javascript
          try67 MVP & Adobe Community Professional

          There are two approaches to this:

          1. Treating the dialog object as a literal object

          2. Treating it as a string

           

          If you treat it as a literal object you can manipulate it like any other object. Each function can be defined separately, and the items in the various arrays can be added or removed as you please.

           

          If you treat it as a string then you can construce that string in a dynamic way, using loops or if-conditions, as you please, and then use the eval() command to convert it to an object when done.

           

          Both approaches are quite complex and require a lot of scripting experience to implement correctly.