5 Replies Latest reply on Jan 31, 2017 11:15 AM by TᴀW

    Simple PDF exporting script from InDesign

    dicom75886549 Level 1

      Hi,

       

      I'm trying for the beginning of my planned script to just export a simple PDF to a destination with the Scripting UI. Here is my code:

       

      var genFenster = new Window ("dialog", "PG beta");

       

       

      // Knopf für das generieren vom PDF Dokument

      var genKnopf = genFenster.add ("button", undefined, "Generieren");

       

       

      genKnopf.onClick = function () {

          app.activeDocument.exportFile(ExportFormat.pdfType, File("testDocument.pdf"), false);

          }

       

       

      genFenster.show ();

       

      Tried to debug it inside ExtendScript but it just enters a loop where it cannot force InDesign to finish it. I've marked with the red color where ExtendScript gets stuck.

      Please help me get this started.

        • 1. Re: Simple PDF exporting script from InDesign
          TᴀW Adobe Community Professional & MVP

          Try something like this:

          var genFenster = new Window ("dialog", "PG beta");
          // Knopf für das generieren vom PDF Dokument
          var genKnopf = genFenster.add ("button", undefined, "Generieren");
          genKnopf.onClick = function () {
              genFenster.close(100);
              }
          var result = genFenster.show();
          if (result === 100){
            app.activeDocument.exportFile(ExportFormat.pdfType, File("testDocument.pdf"), false);
          }
          

           

          The problem with your script is that a modal dialog is open, and when it's open, InDesign can't do anything.

           

          The solution is to close the dialog, and then perform the required InDesign function.

           

          the close() function of a window can take any number, and it is passed to the show() method, so that way you can check what button was pressed, close the window, and act accordingly.

           

          Ariel

          • 2. Re: Simple PDF exporting script from InDesign
            dicom75886549 Level 1

            Thanks man, it works. I can develop it further now. Weird approach. It's important that I understand your code since I need to develop it to reopen the dialog after the export completes.

            • 3. Re: Simple PDF exporting script from InDesign
              TᴀW Adobe Community Professional & MVP

              If you need to reopen the dialog, you may be better off doing things differently.

               

              Instead of using a "dialog"-type window, use a "palette" type window.

               

              Palette-type windows are modeless (like InDesign's Find/Change dialog), which lets the user do things in InDesign even while the dialog is open.

               

              However, it gets a little fiddly with a palette, because as soon as it is opened, the script terminates, and then it is destroyed, so it disappears.

               

              The solution to that is to create a custom script engine, which is much easier than it sounds. So, modifying the example as follows should do the trick:

               

              #targetengine MyNewEngine
              var genFenster = new Window ("palette", "PG beta");
              // Knopf für das generieren vom PDF Dokument
              var genKnopf = genFenster.add ("button", undefined, "Generieren");
              genKnopf.onClick = function () {
                  app.activeDocument.exportFile(ExportFormat.pdfType, File("testDocument.pdf"), false);
              }
              genFenster.show();
              

               

              (By the way, your original suggestion of reopening the window after closing it doesn't work. I seem to recall that once a window is closed, it can't just be reopened with myWindow.show() again...)

               

              Edit: Sorry, I've corrected the script here now (the first version in this post was not demonstrating the use of a palette properly).

              • 4. Re: Simple PDF exporting script from InDesign
                dicom75886549 Level 1

                I've tried it with doScript but your solution is far better. This settles my first step towards my automation script. Thanks so much. Looks like I need to read more into the documentation. I was aware of pallete type just was to scared to implement it, because I was not sure if it would make problems in the future. Seems like it's totally fine.

                • 5. Re: Simple PDF exporting script from InDesign
                  TᴀW Adobe Community Professional & MVP

                  Peter Kahrel makes it all seem so easy:

                   

                  http://www.kahrel.plus.com/indesign/scriptui.html

                   

                  Highly recommended!

                   

                  Ariel