Skip to main content
Participant
July 22, 2021
Answered

Need to save the page by the placed image name

  • July 22, 2021
  • 2 replies
  • 1256 views

Hi

I have a bunch of images I need to resize in on indesign, but want to save the images by the image name that is embedded on the page. I've tried some scripts that have left errors and I've tried the sample catalogue script that doesn't do anything at all. Im at a loss please help me.

 

Thank you 

This topic has been closed for replies.
Correct answer Mike Bro

hello @defaultgckpsw4387fx \ @Morgan5C5D 

 

The below script will export each page within the Indesign document as a jpeg named by the same origional placed jpeg name. The jpegs are exported to a folder on the desktop named jpgs, you'll need to create the jpgs folder on your desktop before hand. You will also need to set the export settings to your specific needs.

 

 

var aDoc = app.activeDocument;
var docPages = aDoc.pages;

for(p=0;p<docPages.length;p++){

var myPageItems = docPages[p].allPageItems
var myPageName = docPages[p].name;

for(i=0;i<myPageItems.length;i++){

//set selection as variable
var thisItem = myPageItems[i];
if(thisItem instanceof Rectangle || thisItem instanceof Polygon || thisItem instanceof Oval){

//get image within the frame
var myLinkedItem = thisItem.pageItems[0];
//get name of the linked image
var myLinkName = myLinkedItem.itemLink.name;

//strip extension from linked image name
var myLinkName = myLinkName.split('.')[0];

app.jpegExportPreferences.jpegQuality = JPEGOptionsQuality.maximum; // low medium high maximum
app.jpegExportPreferences.exportResolution = 300;
app.jpegExportPreferences.jpegExportRange = ExportRangeOrAllPages.exportRange;
app.jpegExportPreferences.pageString = myPageName;

//Set Name of exported pdf to match the name of the linked image
var myFile = File('~/Desktop/jpgs/' + myLinkName + '.jpg');

//export the JPG
aDoc.exportFile(ExportFormat.JPG, myFile, false);
  }
 }
}

 

 

 

Regards,

Mike

2 replies

Mike BroCorrect answer
Legend
July 23, 2021

hello @defaultgckpsw4387fx \ @Morgan5C5D 

 

The below script will export each page within the Indesign document as a jpeg named by the same origional placed jpeg name. The jpegs are exported to a folder on the desktop named jpgs, you'll need to create the jpgs folder on your desktop before hand. You will also need to set the export settings to your specific needs.

 

 

var aDoc = app.activeDocument;
var docPages = aDoc.pages;

for(p=0;p<docPages.length;p++){

var myPageItems = docPages[p].allPageItems
var myPageName = docPages[p].name;

for(i=0;i<myPageItems.length;i++){

//set selection as variable
var thisItem = myPageItems[i];
if(thisItem instanceof Rectangle || thisItem instanceof Polygon || thisItem instanceof Oval){

//get image within the frame
var myLinkedItem = thisItem.pageItems[0];
//get name of the linked image
var myLinkName = myLinkedItem.itemLink.name;

//strip extension from linked image name
var myLinkName = myLinkName.split('.')[0];

app.jpegExportPreferences.jpegQuality = JPEGOptionsQuality.maximum; // low medium high maximum
app.jpegExportPreferences.exportResolution = 300;
app.jpegExportPreferences.jpegExportRange = ExportRangeOrAllPages.exportRange;
app.jpegExportPreferences.pageString = myPageName;

//Set Name of exported pdf to match the name of the linked image
var myFile = File('~/Desktop/jpgs/' + myLinkName + '.jpg');

//export the JPG
aDoc.exportFile(ExportFormat.JPG, myFile, false);
  }
 }
}

 

 

 

Regards,

Mike

rob day
Community Expert
Community Expert
July 23, 2021

Hi Mike, if sizing for social media images is done with InDesign’s Pixel Units, the exportResolution would have to be 72ppi to get a matching exported JPEG pixel dimensions. This image’s parent frame is 500 x 350 pixels, and 72ppi will export it to the same pixel dimensions.

 

 

Legend
July 24, 2021

Hello @rob day 

 

Thanks for pointing out the exportResolution would have to be 72ppi...

 

That's why I stated in my post: "You will also need to set the export settings to your specific needs."

 

Regards,

Mike

m1b
Community Expert
Community Expert
July 22, 2021

Hi, can you clarify? So you have an Indesign document that has a single placed image, and you want to save-as that indesign document as the name of the placed image? eg. if the placed image is "my image.jpeg", the script should save-as the document as "my image.indd"? Also, where should it save the document?

Participant
July 23, 2021

Exactly.  ie The name of the image is Purplet-shirt $20.00, it has been sized to a social media size needs to be saved The Purplet-shirt $20.00.

I am resizing catalogue images to social media size, the images are named specifically. I have impoted all of them, now need to save them by the same origional name as jpegs.

Thank you 

 

 

rob day
Community Expert
Community Expert
July 23, 2021

 it has been sized to a social media size needs to be saved The Purplet-shirt $20.00.

 

For social media you must need a specific pixel dimension. Why not batch that in Photoshop?