how to move image from one page to another page using indesign javascript.
Copy link to clipboard
Copied
hi ,
right now i can able to move image from one place to another place using geometricBounds.. within single page its working fine.
now i want to move the image from one page to another page using indesign javscript.
Copy link to clipboard
Copied
Use move() method, you can specify page as a parameter
#target indesign
myDoc = app.activeDocument;
myImage = myDoc.allGraphics[0].parent;
myPage = myDoc.pages[2];
myImage.move(myPage);
Moves the image to page 3 of the document.
InDesign CS5.5 OSX 10.9
Copy link to clipboard
Copied
Try this,
app.selection[0].move(app.activeDocument.pages[1]);//this line will move the object to second page
Copy link to clipboard
Copied
thank u so much to both of them..both ideas are working fine.
thanks for the support.
Copy link to clipboard
Copied
hi, here is my code.. im trying find the text and match that text with image name. if both are equal , that image will move to under that text .
if text and image are same page, its working fine .but if text and image are in different pages. its not working ..
ImageAlign();
function ImageAlign()
{
var doc = app.activeDocument;
var img = doc.allGraphics;
var finds,myText,myfind,start,end,myPage,imgPage;
app.findTextPreferences = app.changeTextPreferences = NothingEnum.NOTHING;
for(i=0;i<img.length;i++)
{
app.findTextPreferences.findWhat = img.itemLink.name;
finds = doc.findText();
if (finds.length > 0)
{
myPage = finds[0].parentTextFrames[0].parentPage.name;
imgPage = img.parentPage.name;
myFrame = finds[0].parentTextFrames[0].geometricBounds;
finds[0].parentTextFrames[0].textWrapPreferences.textWrapMode = TextWrapModes.BOUNDING_BOX_TEXT_WRAP;
myText = finds[0].createOutlines(false);
gb= myText[0].geometricBounds;
end = gb[0];
start = myFrame[1];
//alert(gb);
//alert(start);
//alert(end);
myText[0].remove();
}
else {
alert('Nothing has been found');
}
//try
//{
if(img.itemLink.name == finds[0].contents)
{
if(myPage == imgPage)
{
img.parent.move([start, end+1.5]);
img.textWrapPreferences.textWrapMode = TextWrapModes.BOUNDING_BOX_TEXT_WRAP;
img.textWrapPreferences.textWrapOffset = [0,1,1,0];
// doc.textFrames[0].move([3,30]);
// alert(img
}
else
{
img.parent.move(doc.pages[myPage]);
img.parent.move([start, end+1.5]);
img.textWrapPreferences.textWrapMode = TextWrapModes.BOUNDING_BOX_TEXT_WRAP;
img.textWrapPreferences.textWrapOffset = [0,1,1,0];
}
}
//catch(e)
//{
//alert('There is no match in this document');
//}
app.findTextPreferences = app.changeTextPreferences = NothingEnum.NOTHING;
}
}
Copy link to clipboard
Copied
Try this,
img.parent.move(doc.pages[Number(myPage)-1]);
Copy link to clipboard
Copied
thank u so much . i used this code and its working fine,.
Copy link to clipboard
Copied
now im getting error in that line. when i try to run this script in another document.
Copy link to clipboard
Copied
Check what all your references are correct, check that there is a page, check there is a graphic frame and there is an image in it.
Copy link to clipboard
Copied
yeah i checked everything is there in my document.
image is there in page 2 and text references is there in page 5.
now image has to move to page 5. but im getting this error..
Copy link to clipboard
Copied
Is it one image only does not work, or you only have one image to move? If it is the case, try to move it explicitly:
img.parent.move(doc.pages[4]);
Disable everything else - second move and text-wrap.
Copy link to clipboard
Copied
Not sure if move will work for inline image. I would try to get the filepath, remove the image and place it again at the found[0] insertion point
Copy link to clipboard
Copied
now i found , in my document i have 15 pages but i have only one text frame and that text frame is extended to 15 pages ..
i think thats why im getting this error..now how to resolve this ..
Copy link to clipboard
Copied
no i have 5 different images in my document.
here this program concept is , i have to move the images to its correct location.
Copy link to clipboard
Copied
I see. You problem is this line:
myPage = finds[0].parentTextFrames[0].parentPage.name;
You need to get the page of your finds[0].
Check what you get for parentPage above, it might be an array of all pages.
So if you add myPage = finds[0].parentTextFrames[0].parentPage[0].name; this might move your image to the first page.
Copy link to clipboard
Copied
This works for me (CS 5.5 OSX 10.9):
myPage = finds[0].parentTextFrames[0].parent.pages[0].name;
Copy link to clipboard
Copied
see this line gives the correct page number where the image name text is present.
myPage = finds[0].parentTextFrames[0].parentPage.name;
but i'm getting error in this line..
img.parent.move(doc.pages[Number(myPage)-1]);
Copy link to clipboard
Copied
i can move images inside the same page but if i want to move the page to some other page . it showing error in this line.
img.parent.move(doc.pages[Number(myPage)-1]);
Copy link to clipboard
Copied
Check if doc.pages[Number(myPage)-1] evaluates to a page.
I suspect that image parent is different, could you do alert(img.parent);?
Copy link to clipboard
Copied
yeah,
i checked and alert(doc.pages[Number(myPage)-1]); it shows the correct page object.
i did alert(img.parent); and correctly it shows the rectangle object of that image.
Copy link to clipboard
Copied
OK, try to add these two lines:
img.parent.anchoredObjectSettings.anchoredPosition = AnchorPosition.ANCHORED;
img.parent.anchoredObjectSettings.releaseAnchoredObject();
img.parent.move(doc.pages[Number(myPage)-1]);
I suppose, the image you placed is anchored to the text. You need to release the parent rectangle before you move it.
Nicolai
Copy link to clipboard
Copied
yeah i add this two lines , but it showing error in this line..
Copy link to clipboard
Copied
You need to investigate the object.
What is img.parent.anchoredObjectSettings.anchoredPosition ?
Is your image inline? Can you manually move it to a different page, different spread?
I checked the dom reference for CS6 and all it looks fine.
Copy link to clipboard
Copied
this below code , showing INLINE_POSITION ...
alert( img.parent.anchoredObjectSettings.anchoredPosition);
and its working ..but first time its releasing the anchoredposition of the image .
next time while i run this script .. it showing error like ..
"the property is not applicable in the current state...
because the anchoredposition is released ..
now i need a condition like,,
wheather the image is anchored or not...

