Mass export all images as individual JPEGs in InDesign, but not use image frame ratio

I would like to mass export all linked images in a Indesign document using this script, its from this thread

var myDoc = app.activeDocument,
apis = myDoc.allPageItems, pageItem, fileName;

while ( pageItem = apis.pop() ) {
  if ( !pageItem.graphics[0].isValid ){ continue;}

  fileName = File ( pageItem.graphics[0].itemLink.filePath ).name;
  fileName = fileName.replace( /\.[a-z]{2,4}$/i, '.jpg' );

  app.jpegExportPreferences.exportResolution = 2400;
  app.jpegExportPreferences.jpegQuality = JPEGOptionsQuality.MAXIMUM;

  //give it a unique name
  var myFile = new File ("C:/Users/RANFacistol-Mata/Desktop/Image Trial/"+ fileName);


  pageItem.exportFile(ExportFormat.JPG, myFile);
}

When i use this script, it export the linked images in the ratio how its placed in Indesign.

How its exported
enter image description here

How it looks in Indesign
enter image description here

Yet i want it to look like this, the original ratio of the image
enter image description here

Answer

You need to export the graphic, not the object.
Add .graphics[0] before the exportFile function.

var myDoc = app.activeDocument,
    apis = myDoc.links.everyItem().getElements(),
    items, fileName;
var i = 0;
var MyPath = "C:/Users/xx/Desktop/test/"; // change your path here

alert("Script is running. Press OK and wait until done...");

while (items = apis.pop()) {
    items = items.parent.parent;
    if (!(items.hasOwnProperty("graphics"))) {
    continue;
    }
    i++;
    try {
        fileName = File(items.graphics[0].itemLink.filePath).name;
        fileName = i + "_" + fileName.replace(/\.[a-z]{2,4}$/i, '.jpg');
    } catch (e) {};

    app.jpegExportPreferences.exportResolution = 2400;
    app.jpegExportPreferences.jpegQuality = JPEGOptionsQuality.MAXIMUM;

    //give it a unique name
    var myFile = new File(MyPath + fileName);

    items.graphics[0].exportFile(ExportFormat.JPG, myFile);
}

alert("Done");

Edit: Or… package your links and use Photoshop batch function to save everything in JPG

Attribution
Source : Link , Question Author : Rombout Versluijs , Answer Author : Vinny

Leave a Comment