0

I'm struggling with a problem where I need to get JPGs of all the written questions in InDesign since I work at a school. To make the process faster, I decided to go the "Export Objects" way. But i couldn't find a suitable script to achieve what I need.

Basically,

  • Select All Text Frames in the given Layout(Alternates are present)
  • Export All Text frames as JPG with given DPI value and name variable.

Both actions are actually available with the Sample codes, but in a different way. For example: SelectObject script works, but when combined with Command+E, the export result is one big image that contains all the selected frames. I want them separately.

I've tried combining the scripts given as applescript or js with my little knowledge of coding but no cigar.

Select Text : Indesign CC 2018 - SelectObjects Sample Code. Image export: Indesign CC 2018 - Export to JPG scripts are the codes I've tried mingling with.

Goal: Export all text frames individually as variable DPI, variable name and variable destination from separate alternate layouts.

Edit 1: Code that I'm trying to mingle with. I found it on reddit but even though it essentially does what i need, it does in a crooked way and unusable. IT exports ALL items and they are with the page background, I'd need only the stuff that are contained within the TextFrame.

// Set resolution options
  var rp = [72,150,300];

// Set EXPORT presets
    app.pngExportPreferences.exportResolution = 72;
    app.pngExportPreferences.antiAlias = true;
    app.pngExportPreferences.pngQuality = PNGQualityEnum.MAXIMUM;
    app.pngExportPreferences.pngColorSpace = PNGColorSpaceEnum.RGB;
    app.pngExportPreferences.pngExportRange = PNGExportRangeEnum.EXPORT_RANGE;

// Resolution Select Dialog
  var w;    
  w = new Window('dialog', 'Export Presets');  
  w.orientation = 'row';
  with (w) 
    {
       w.sText = add('statictext', undefined, 'Select Export Resolution:');
       w.dropdown = add ( 'DropDownList',undefined,undefined,{items:rp});
       w.btnOK = add('button', undefined, 'OK');
    };
  w.dropdown.selection=0; 
  w.show();  

  // Set resolution
      var x = 0;
      x = x + w.dropdown.selection;
    app.pngExportPreferences.exportResolution = rp[x];

// SElECT Folder locations
  var myFileAmount = 0; 
  var myFileLocation = Folder.selectDialog("Please select path of InDesign Files");
  myFolder = new Folder ([myFileLocation]);
  myFolderContents = myFolder.getFiles("*.indd"); // array
  myFileAmount = (myFolderContents.length - 1); 

  // CHECK IF FILES IN FOLDER
    if (myFileAmount < 0){alert("No Files in selected folder");}
    else
      {
        var mySaveLocation = Folder.selectDialog("Please select path to Save PNG");
        mySaveFolder = new Folder ([mySaveLocation]);

      // OPEN FILES One at a time
      for (i = myFileAmount; i >= 0; i--)
        { 
          app.open(File (myFolderContents[i]));
          app.scriptPreferences.userInteractionLevel = UserInteractionLevels.NEVER_INTERACT;

          // SET Active Document
          var myDoc = app.activeDocument;

              // EXPORT

          //One Page at a time
          for (var p=0; p < myDoc.pages.length; p++)
            {//page loop
             var pname = myDoc.pages.item(p).name; 

             //set all items in file hiden
             for (var itemnum=0;itemnum < myDoc.pages.item(p).pageItems.length; itemnum++)
              {
                myDoc.pages.item(p).pageItems.item(itemnum).visible = false;
              }

             // set page to export
             app.pngExportPreferences.pageString = pname;

             //add a 0 in from on less than 10
             if (p<9){var pnm=0;}else{var pnm=""}

              //LOOP Through items Set Visibility, export a PNG, Set Visibility
             for (var itemexport=0;itemexport < myDoc.pages.item(p).pageItems.length; itemexport++)
               {
                var itm = itemexport+1;//items start at 1 not 0
                myDoc.pages.item(p).pageItems.item(itemexport).visible = true;
                //ACTUALLY EXPORTING
                app.activeDocument.exportFile(
                 ExportFormat.PNG_FORMAT, 
                File(mySaveFolder.fsName + "/" + app.activeDocument.name.split(".indd")[0]  + "_"+ pnm + pname + "_" + itm +".png"),
                false, 
                   );
                //SET VISIBILITY
                myDoc.pages.item(p).pageItems.item(itemexport).visible = false;
        }  
      }

       app.activeDocument.close(SaveOptions.no);
    }
}                                                           
Sved
  • 15
  • 3
  • Can you please [edit your question](https://stackoverflow.com/posts/54197778/edit) with the code you have so far? – cybernetic.nomad Jan 15 '19 at 19:42
  • To be honest, I have no code that I could say "I've made this" and take credit for, I tried to edit and merge 2 codes and I figured that probably is not the right way to approach this. Hence why I'm here. I could still post the example code and the code I found on the webs here tho. Albeit not mine at all. – Sved Jan 16 '19 at 04:56
  • The point is to give us something to look at. It will probably be easier to debug existing code that come up with it from scratch. – cybernetic.nomad Jan 16 '19 at 15:04
  • @cybernetic.nomad edited the original post to include the most recent code i found. – Sved Jan 16 '19 at 17:01
  • @cybernetic.nomad I figured out how to export all text frames but ran into masterpage problems. Question on different thread. https://stackoverflow.com/questions/54282432/how-to-exclude-masterpage-items-when-bulk-exporting-all-text-frames – Sved Jan 21 '19 at 01:16

0 Answers0