Functions for Links
Written by Kasyan
Link usage
function LinkUsage(link) {
var links = gDoc.links;
var counter = 0;
for (var i = 0; i < links.length; i++) {
if (link.filePath == links[i].filePath) {
counter++;
}
}
return counter;
}
Find the largest link
function FindLargestLink(link) {
var theLargestLink, theLink, image, horScale, verScale;
var links = gDoc.links;
var multyLinks = [];
for (var i = 0; i < links.length; i++) {
if (link.filePath == links[i].filePath) {
multyLinks.push(links[i]);
}
}
for (var k = 0; k < multyLinks.length; k++) {
theLink = multyLinks[k];
image = theLink.parent;
horScale = image.absoluteHorizontalScale;
if (theLargestLink == undefined) {
theLargestLink = theLink;
}
else if (horScale > theLargestLink.parent.absoluteHorizontalScale) {
theLargestLink = theLink;
}
}
return theLargestLink;
}
Update all outdated links
function UpdateAllOutdatedLinks() {
var link;
for (var i = gDoc.links.length-1; i >= 0; i--) {
link = gDoc.links[i];
if (link.status == LinkStatus.LINK_OUT_OF_DATE) link.update();
}
}
How to find the MIME type of a link
var mimetype = {
jpg:'image/jpeg',
jpe:'image/jpeg',
jpeg:'image/jpeg',
png:'image/png',
pdf:'application/pdf'
};
imgs = app.activeDocument.allGraphics;
result = [];
for (i=0; i<imgs.length; i++)
result.push(imgs[i].itemLink.filePath+' = '+mimetype[String(imgs[i].itemLink.filePath.match(/[^.]+$/)).toLowerCase()]);
alert(result.join('\r'));
List all links — writes the list of all links in the active document into the ESTK console
