0 Replies Latest reply on Apr 6, 2015 10:53 AM by RyanJForth

    How can I auto export a PDF File using the "Smallest File Size" preset and set the Exported File Name based on information from an Imported PDF?


      Greetings all,


      I am trying to create a script to automate a PDF export process for my company for inDesign. I’m fairly new to inDesign itself and have no previous experience with javascript, although I did take C++ in high school and have found it helpful in putting this code together.


      We have an inDesign template file and then use the Multi-page PDF importer script to import PDF files. We then have to export two version of each file that we import, then delete the imported file and all of the pages to reset the template. This has to be done for nearly 1000 pdf files each month and is quite tedious. I’m working on automating the process as much as possible. I’ve managed to piece together code that will cleanup the file much quicker and am now trying to automate the PDF exports themselves.


      The files are sent to us as “TRUGLY#####_Client” and need to be exported as “POP#####_Client_Date-Range_North/South.pdf”


      For example, TRUGLY12345_Client needs to be exported as POP12345_Client_Mar01-Mar31_North and POP12345_Client_Mar01-Mar31_South.


      There are two templates built into the template file for the north and south file that are toggled easily via layer visibility switches. I need to get a code that can ideally read the #s from the imported Trugly file as well as the Client and input those into variables to use when exporting. The date range is found in the same place in the top right of each pdf file. I am not sure if this can be read somehow or if it will have to be input manually. I can put North or South into the file name based on which template layer is visible.


      I am not sure how to go about doing this. I did find the following code for exporting to PDF with preset but it requires me to select a preset and then type the full file name. How can I set it to automatically use the “Smallest File Size” preset without prompting me to choose and then automatically input some or preferably all of the file name automatically? (If the entire filename is possible then I don’t even want a prompt to appear so it will be fully automated!)


      PDF Export Code (Originally from here: Simple PDF Export with Preset selection | IndiSnip [InDesign® Snippets]):


      var myPresets = app.pdfExportPresets.everyItem().name;

      myPresets.unshift("- Select Preset -");


      var myWin = new Window('dialog', 'PDF Export Presets');

      myWin.orientation = 'row';


          myWin.sText = add('statictext', undefined, 'Select PDF Export preset:');

          myWin.myPDFExport = add('dropdownlist',undefined,undefined,{items:myPresets});

          myWin.myPDFExport.selection = 0;

          myWin.btnOK = add('button', undefined, 'OK');



      var myWindow = myWin.show();


      if(myWindow == true && myWin.myPDFExport.selection.index != 0){

          var myPreset = app.pdfExportPresets.item(String(myWin.myPDFExport.selection));

          myFile = File(File.saveDialog("Save file with preset: " + myPreset.name,"PDF files: *.pdf"));

          if(myFile != null){

              app.activeDocument.exportFile(ExportFormat.PDF_TYPE, myFile, false, myPreset);


              alert("No File selected");



          alert("No PDF Preset selected");




      So far my code does the following:

      1) Runs the Multi-Page PDF Import Script

      2) Runs PDF Export Script Above

      3) Toggles the Template

      4) Runs #2 Again

      5) Deletes the imported PDF and all pages and toggles template again.


      It’s close and much better than the original process which was almost 100% manual but I’d like to remove the Preset prompt from the PDF script and have it automatically select the “Smallest File Size” preset. and then if there’s a way to have it auto-fill in the file name so no user input is required at all other than selecting each file to import. (If there’s a way to setup a batch action for the multi-import script that would be even better!)


      Thanks in advance and if there’s anything else I can provide that would help please let me know! Even a nudge in the right direction will be a big help!