11 Replies Latest reply: Jun 13, 2008 11:22 AM by Kasyan Servetsky RSS

    [JS- CS3] Before Export Set pdfExportPresets

    David Pitsford Community Member
      I am having trouble setting the pdfExportPreset with a script I am using to do things before the Export Dialog box shows up.

      I can set the pdfExportPreferences.pageRange with no problem. But can't get the pdfExportPresets to work.

      Var myPreSet = app.pdfExportPresets.item("PDF Preset1");
      with(app.pdfExportPresets){
      name = myPreSet.name;
      }

      Mahalo
      David
        • 1. Re: [JS- CS3] Before Export Set pdfExportPresets
          Community Member
          Hi David,

          This is how I do it when I import XML into a batch folder and export them as PDFs. I also save the INDD file just in case I need to edit them at a later date.

          // Import XML into templats
          var myTemplate = File.openDialog("C:\temp");
          var myFolder = Folder.selectDialog("C:\temp");
          var myDocs = myFolder.getFiles("*.xml");
          for (i = 0; i < myDocs.length; i++) {

          // I put a lot of formatting functions in here...
          exportToPDF();
          saveFiles();

          // Export to PDF.
          function exportToPDF() {
          var myPDFExportPreset = app.pdfExportPresets.item("myPreset");
          var newFileName = myFolder.absoluteURI + '/' + myDoc[i].name.replace(/xml/, "PDF");
          app.activeDocument.exportFile(ExportFormat.pdfType, File(newFileName), false, myPDFExportPreset);
          }

          // Save
          function saveFiles() {
          var newFileName = myFolder.absoluteURI + '/' + myDocs[i].name.replace(/xml/, "indd");
          newDoc.save(new File(newFileName));
          app.activeDocument.close();
          }
          }

          I'll leave it up to you to tweak it for your script ;-). Hope this helps.

          Brett
          • 2. Re: [JS- CS3] Before Export Set pdfExportPresets
            Community Member
            Sorry David,

            I get what your doing after I re-read your post. Do you need to set the preset from script because you are running this on several different computers?

            If not then you could just manually create a preset in the InDesign GUI and call upon that as shown in the script above.

            I don't know if you can create a preset from script but you can edit the 'pdfExportPreferences' when exporting (it's in the guide), for example:

            function exportToPDF(){
            with (app.pdfExportPreferences){
            pageRange = PageRange.allPages;
            acrobatCompatibility = AcrobatCompatibility.acrobat6;
            exportGuidesAndGrids = false;
            //etc
            }}

            Regards,
            Brett
            • 3. Re: [JS- CS3] Before Export Set pdfExportPresets
              David Pitsford Community Member
              Thanks for replying Brett.
              I have the preset already loaded on all of our machines.

              What I want to do is have the preset automatically be selected by the time the dialog box comes up. So the users don't have to choose it from the pull down.

              I am using the same code you gave me for the pdfExportPreferences pageRange. that works. I am having trouble getting the proper code to make the preset always be "PDF Preset1".

              David
              • 4. Re: [JS- CS3] Before Export Set pdfExportPresets
                Kasyan Servetsky Community Member
                Hi David,

                To make sure that your script always uses a certain PDF preset you can do it like so:
                //Your PDF Export Preset is the name of your PDF preset as you see it in the user interface.

                if (app.pdfExportPresets.item("Your PDF Export Preset") != null){
                
                   myDocument.exportFile(ExportFormat.pdfType, myFile, false, "Your PDF Export Preset");
                }
                else {
                   alert("Your PDF Export Preset is not installed");
                   exit();
                }


                If you want to set the name of a preset as default in a dialog, you can do it like in this example:
                myDoc = app.activeDocument;
                
                fileNameWOExt = myDoc.name.split(".indd").join("");
                var myPDFExportPreset = app.pdfExportPresets.item("Your PDF Export Preset");
                var myPresetIndex = myPDFExportPreset.index;
                pdfPresetDialog = app.dialogs.add();
                with (pdfPresetDialog.dialogColumns.add()) {
                  with (dialogRows.add()) {
                    with (dialogColumns.add()) {
                      staticTexts.add({staticLabel: "Choose PDF-export preset:"});
                      with (dialogRows.add()) {
                        pdfDD = dropdowns.add();
                        sl = new Array();
                        for (i=0; i < app.pdfExportPresets.length; i++)
                          sl.push(app.pdfExportPresets[i].name);
                          pdfDD.stringList = sl;
                          pdfDD.selectedIndex = myPresetIndex;
                      }
                    }
                    dialogColumns.add().staticTexts.add({staticLabel: " ", minWidth: 15});
                    with (dialogColumns.add()) {
                      dialogRows.add().staticTexts.add({staticLabel: "Name your file:"});
                      pdfFileName = dialogRows.add().textEditboxes.add({editContents:fileNameWOExt + ".pdf", minWidth: 100});
                    }
                    dialogColumns.add().staticTexts.add({staticLabel: " ", minWidth: 15});
                  }
                }
                pdfPresetDialog.show();


                Kasyan
                • 5. Re: [JS- CS3] Before Export Set pdfExportPresets
                  David Pitsford Community Member
                  Thanks Kasyan.
                  But I don't want to create my own export dialog box. I would prefer to use the build in one.

                  David
                  • 6. Re: [JS- CS3] Before Export Set pdfExportPresets
                    Kasyan Servetsky Community Member
                    David,

                    I haven't got quite well the idea what you want to achieve. Why do you need to open built in dialog when you can set all the setting you need by the script? If I got you right, you want to open it and have some PDF-preset selected in it but I think it's impossible to do. At least my attempt to attain this was futile.

                    Kasyan
                    • 7. Re: [JS- CS3] Before Export Set pdfExportPresets
                      David Pitsford Community Member
                      I want to use the built in application Export dialog.

                      Yes I would like to have that dialog automatically have a certain Preset selected.

                      I. Like you, can't seem to get that to work. I can get everything else under the pdfExportPreferences to be set the way I want it in the application Export dialog.

                      David
                      • 8. Re: [JS- CS3] Before Export Set pdfExportPresets
                        Community Member
                        Hi David,

                        The script that I originally posted selects and uses the preset without any interaction from the user. Have you tried it?

                        app.activeDocument.exportFile(ExportFormat.pdfType, File(newFileName), false, myPDFExportPreset);

                        Brett
                        • 9. Re: [JS- CS3] Before Export Set pdfExportPresets
                          David Pitsford Community Member
                          I am using a beforeInvoke on Export event listener in a Startup script.
                          • 10. Re: [JS- CS3] Before Export Set pdfExportPresets
                            Hi
                            How can I create a new pdfExportPreferences using javascript?
                            I'm use many computers and i can't create the preset in all machines together.
                            I try use this script

                            var myPDFExportPreset = app.pdfExportPresets.add;
                            myPDFExportPreset.name = "MY-PRESET";

                            but, don't create a new preset.

                            Why?

                            Thanks

                            Carlos Cubas
                            • 11. Re: [JS- CS3] Before Export Set pdfExportPresets
                              Kasyan Servetsky Community Member
                              Hi Carlos,

                              add is a method, so it should be followed by parentheses:

                              var myPDFExportPreset = app.pdfExportPresets.add();

                              Kasyan