Copy link to clipboard
Copied
Windows 10 64bit or iMac 2019 - both running Adobe CC 2020 apps.
I have multiple InDesign files that are about 250 pages each. My client wants me to replace anywhere from 30 - 40 pictures per file with new images. Is there a JavaScript file that can do this? I imagine I would have to enter the existing image file names along with the new file names into such a script, if it exists.
Copy link to clipboard
Copied
There is the relink panel. You can hold shift to multi-select. Otherwise, yeah, something like:
var arr = [
["oldName.jpg", "full/path/to/newimage.jpg"],
["oldName2.pdf", "full/path/to/newName2.pdf"],
//etc.
];
var theLink;
var theDoc = app.documents[0];
for (var i =0; i < arr.length; i++) {
theLink = theDoc.links.itemByName(arr[i][0]);
theLink.relink(File(arr[i][1]);
}
You'll run into issues, though, if the same link is used multiple times in a doc.
You can also look at this existing relink script: https://indesignsecrets.com/a-script-for-relinking-images.php
Copy link to clipboard
Copied
Thanks for your reply! What kind of issue would I run into if the same pic is used multiple times? Won't it just replace all instances of it with the new pic?
Copy link to clipboard
Copied
Because itemByName will only grab one link. We probably have to iterate through the whole link list instead. Maybe something like this, but could probably use refinement. Note the syntax change from using an array to object:
var theObj = {
"oldName.jpg": "full/path/to/newimage.jpg",
"oldName2.pdf": "full/path/to/newName2.pdf",
//etc.
};
var theLinks = app.documents[0].links.everyItem().getElements();
for (var i =0; i < theLinks.length; i++) {
if (theObj.hasOwnProperty(theLinks[i].name)) {
try {
theLinks[i].relink(File(theObj[theLinks[i].name]));
} catch(e) {}
}
}