4 Replies Latest reply on Jan 18, 2017 2:22 AM by Ananth@desgin

    Create PDF files using User Interface

    Ananth@desgin Level 3

      Hi All,

      I have created some code for create PDF files using User Interface. But i get error message. "Cannot handle the request because a model dialog or alert is active". My output will be if i click radio button 1 i will get Hi-res PDF files.

       

      I tried to modify you coding for creating pdf files, but not working as expected.

       

      var window = new Window ("dialog");

      window.alignChildren = "left";

      var radio1 = window.add ("radiobutton", undefined, "Hi-res_PDF");

      var radio2 = window.add ("radiobutton", undefined, "Low_res_PDF");

      var radio3 = window.add ("radiobutton", undefined, "PRINTER");

      var myOkButton = window.add ("button", undefined, "OK");

      var myCancelButton = window.add ("button", undefined, "Cancel");

      myOkButton.onClick = function()

      {

      if(radio1.value == true;)

      {

      var myPDFExportPreset = app.pdfExportPresets.item("Smallest file size"); // Change myPDFpreset to the name of the preset you want to use

      var myFileLocation = Folder.selectDialog("Please select path to files");

      myFolder = new Folder ([myFileLocation]);

      myFolderContents = myFolder.getFiles("*.indd"); // array

      myFileAmount = (myFolderContents.length - 1);

      // ===== Open, Export as PDF, and Close files ===== \\

      for (i = myFileAmount; i >= 0; i--)

      app.open(File (myFolderContents[i]));

      app.activeDocument.exportFile(

        ExportFormat.pdfType, 

        File(myFolder.fsName + "/" + app.activeDocument.name.split(".indd")[0] + ".pdf"),

        false, 

        myPDFExportPreset

        );

      app.activeDocument.close(SaveOptions.no);

       

      }

      }

      }

      window.show ();

       

      Thanks,

      Prabu G

        • 1. Re: Create PDF files using User Interface
          S Hopkins Adobe Community Professional

          I wonder why you are using a window for a dialog. Yes it can be done, but can raise a problem if you do not destroy the window after creating it. Try using InDesign's dialog object instead. Here is a sample for working with radio button controls. Notice setting for userInteractionLevel; without this setting the dialog will not show. You might want to save the current script preference value in a variable  to restore its value when the script is through.

           

          //Result from dialog will return 0, 1, or 2 to correspond with Hi-res, Low-res, or PRINTER

          try { 

              //provide variable to hold user's response

              var userResponse = dialogWRadio ("PDF Preferences", true, "PDF Prefs");

              alert ("user entered " + userResponse);

             } catch (e) {

              alert (e);

             }

           

          function dialogWRadio (dlgName, cancelIt, dlgLabel) {

              var userCancelled = true;

             app.scriptPreferences.userInteractionLevel=UserInteractionLevels.INTERACT_WITH_ALL;

             //create dialog in memory

              var dlgRef = app.dialogs.add({name:dlgName, canCancel:cancelIt, label:dlgLabel});

               var dlgColumn = dlgRef.dialogColumns.add();

               //add a row

               var dlgRow = dlgColumn.dialogRows.add();

               //add radio elements to row

               var rGroup = dlgRow.radiobuttonGroups.add();

               rGroup.radiobuttonControls.add({staticLabel:"Hi-res_PDF", checkedState:true});

               rGroup.radiobuttonControls.add({staticLabel:"Low-res_PDF"});

               rGroup.radiobuttonControls.add({staticLabel:"PRINTER"});

              //show the dialog

              if (dlgRef.show() == true) {

                  userCancelled = false;

                     var radioValue = rGroup.selectedButton;

              }

             //destroy the dialog

            dlgRef.destroy();

            //handle result

            if (userCancelled) {

               throw ("User Cancelled");

             }

            return radioValue;

          }

          1 person found this helpful
          • 2. Re: Create PDF files using User Interface
            Ananth@desgin Level 3

            Hi,

             

            Sorry for the delayed response.

             

            Your code is helpful to complete my process..

             

            Thanks,

            Prabu G

            • 3. Re: Create PDF files using User Interface
              Loic.Aigon Adobe Community Professional

              Hi

               

              It's a classic. When you use a dialog whatever it's scriptUI (in dialog type) or InDesign dialog object, your window is modal meaning that you cannot interact with InDesign at this tile. You need to close your dialog first then run your routine…

               

              var window = new Window ("dialog");
              window.alignChildren = "left";
              var radio1 = window.add ("radiobutton", undefined, "Hi-res_PDF");
              var radio2 = window.add ("radiobutton", undefined, "Low_res_PDF");
              var radio3 = window.add ("radiobutton", undefined, "PRINTER");
              var myOkButton = window.add ("button", undefined, "OK");
              var myCancelButton = window.add ("button", undefined, "Cancel");
              myOkButton.onClick = function()
              {
                //Closing dialog indicating a call for action => 1
                window.close(1);
              }
              
              
              //If dialog returned 1, then routine has to be executed…
              if ( window.show ()==1 ) {
                if(radio1.value == true;)
                {
                var myPDFExportPreset = app.pdfExportPresets.item("Smallest file size"); // Change myPDFpreset to the name of the preset you want to use
                var myFileLocation = Folder.selectDialog("Please select path to files");
                myFolder = new Folder ([myFileLocation]);
                myFolderContents = myFolder.getFiles("*.indd"); // array
                myFileAmount = (myFolderContents.length - 1);
                // ===== Open, Export as PDF, and Close files ===== \\
                for (i = myFileAmount; i >= 0; i--)
                { 
                app.open(File (myFolderContents[i]));
                app.activeDocument.exportFile(
                 ExportFormat.pdfType, 
                 File(myFolder.fsName + "/" + app.activeDocument.name.split(".indd")[0] + ".pdf"),
                 false, 
                 myPDFExportPreset
                 );
                app.activeDocument.close(SaveOptions.no);
                 
                }
                }
              }
              

               

              HTH

               

              Loic

              http://www.ozalto.com/

              1 person found this helpful
              • 4. Re: Create PDF files using User Interface
                Ananth@desgin Level 3

                Hi Aigon,

                 

                This worked perfectly! It was exactly the script I was looking for. Thanks so much, you're awesome!!!