Skip to main content
Known Participant
July 10, 2015
Question

how to move image from one page to another page using indesign javascript.

  • July 10, 2015
  • 14 replies
  • 3407 views

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.

This topic has been closed for replies.

14 replies

mani4Author
Known Participant
July 10, 2015

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.geometricBounds);

     }

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;

}

}

Legend
July 11, 2015

Try this,

img.parent.move(doc.pages[Number(myPage)-1]);

mani4Author
Known Participant
July 10, 2015

thank u so much to both of them..both ideas are working fine.

thanks for the support.

Legend
July 10, 2015

Try this,

app.selection[0].move(app.activeDocument.pages[1]);//this line will move the object to second page

Inspiring
July 10, 2015

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