Remove the same image in multiple pages

Community Beginner ,
Apr 22, 2021 Apr 22, 2021

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

TOPICS
How to, Scripting

Views

435

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 2 Correct answers

Adobe Community Professional , Apr 22, 2021 Apr 22, 2021
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...

Likes

Translate

Translate
Adobe Community Professional , Apr 22, 2021 Apr 22, 2021
Is your selected image a linked image or is it pasted? Are you getting the Select a linked image alert?

Likes

Translate

Translate
Adobe Community Professional ,
Apr 22, 2021 Apr 22, 2021

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...

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Apr 22, 2021 Apr 22, 2021

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?

 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Apr 22, 2021 Apr 22, 2021

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")
}  

 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Apr 22, 2021 Apr 22, 2021

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.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Apr 22, 2021 Apr 22, 2021

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?

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Apr 22, 2021 Apr 22, 2021

Copy link to clipboard

Copied

LATEST

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.

 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines