Copy link to clipboard
Copied
Hi everyone!
I have two problems that although they are trivial it seems there isn't any script for these.
• I have a document with multiple pages, and the same image on almost any page. I need to remove the image from all the pages
• the same multiple-pages document but this time I want to remove not only the image but the entire page where the image is placed.
Does someone know if there is a script able to do something like that?
thanks
Hi,
I think you could work from the links panel, get each link, check it is the one you want to remove, if so get the pageItem(s) from the link(s) and then remove them, For part two you could do the same, but rather than stopping at the pageItem, you could get the page and remove it, although be careful as the pages will be re-ordered as soon aas you remove one, so best to work from the end of the document back to the start.
// Deleting the images - only covers image type, may need to modify
...
Is your selected image a linked image or is it pasted? Are you getting the Select a linked image alert?
Copy link to clipboard
Copied
Hi,
I think you could work from the links panel, get each link, check it is the one you want to remove, if so get the pageItem(s) from the link(s) and then remove them, For part two you could do the same, but rather than stopping at the pageItem, you could get the page and remove it, although be careful as the pages will be re-ordered as soon aas you remove one, so best to work from the end of the document back to the start.
// Deleting the images - only covers image type, may need to modify.
var allLinks = app.activeDocument.links.everyItem().getElements();
for (var i = allLinks.length-1; i >= 0; i--){
var curLink = allLinks[i];
if (curLink.name == "20161017-IMG_6134.jpg"){
var curParent = curLink.parent.remove();
}
}
And then for pages you can use the same loop as above, but call "curLink.parent.parentPage() and the will give you the page, which you can also call remove(); (note you have to have a least one page in a document.)
This is just a starting point for your scripts depending on the complexity of your documents you may need to add some extra steps, tables, anchored image, etc...
Copy link to clipboard
Copied
Thank BarlaeDC,
I have tested it and it works for deleting single images, but I cannot be able to make it works with pages.
Is it possible that it is because the link the script has to target is a pdf and not a jpg?
Copy link to clipboard
Copied
You could also select one of the multiple images to get its link name, then delete any pages containing a link with the same name. Something like this might work:
try {
var n = app.activeDocument.selection[0].itemLink.name;
var allLinks = app.activeDocument.links;
for (var i = allLinks.length-1; i >= 0; i--){
if (allLinks[i].name == n){
allLinks[i].parent.parentPage.remove();
}
}
}catch(e) {
alert("Select a linked image")
}
Or for just the images this removes the image and its container frame
try {
var n = app.activeDocument.selection[0].itemLink.name;
var allLinks = app.activeDocument.links;
for (var i = allLinks.length-1; i >= 0; i--){
if (allLinks[i].name == n){
allLinks[i].parent.parent.remove();
}
}
}catch(e) {
alert("Select a linked image")
}
Copy link to clipboard
Copied
Hi Rob Day,
it works (I have tried the first one) with every image but the actual one I need to delete. I don't understand why.
Copy link to clipboard
Copied
Is your selected image a linked image or is it pasted? Are you getting the Select a linked image alert?
Copy link to clipboard
Copied
I got the Select a linked image alert.
However, I tried several times and it does not work if the name of the link contains _.
For example, if the name of the link is image_2.jpg it does not work, while if it is image2.jpg it works.