Skip to main content
October 10, 2013
Answered

Reg. Place image in textframe

  • October 10, 2013
  • 2 replies
  • 1537 views

HI All,

I have been struggling lot to place an image near to the find text. From the below code snippet I could place the image but it is placing in anchor frame.

Since the image in anchor frame, the text wrap preferences could not apply.

var myFoundItems = new Array;

var mydoc = app.activeDocument;

app.findTextPreferences = null;

app.findTextPreferences.findWhat = "<F1><\F2>";

myFoundItems = app.activeDocument.findText();

for (var i = 0; i < myFoundItems.length; i++)

{

    var myFile = File(myFilteredimages); // Array contains images - myFilteredimages

    if(myFile.exists)

    {

        myFoundItems.place(myFile);

    }

}

I do not want to place the image in anchor frame, Please help me out in this.

Thank a lot.

Regards,

Sathya Rani M

This topic has been closed for replies.
Correct answer

Thank you for the reply. I have placed the image to the found textframe parent.

Please see the piece of code below.

for(k = 0; k < myTagnames.length; k++)

{

    app.findTextPreferences = null;

    app.findTextPreferences.findWhat = myTagnames;

    myFoundItems = app.activeDocument.findText();

    for (var i = 0; i < myFoundItems.length; i++)

    {

        progress.value = i+1;

        var myFile = File(myFilteredimages);

        myFrame = myFoundItems.parentTextFrames[0];

        if(myFile.exists)

        {

            app.select(myFrame.parent);

            PlaceIntoFrame(myFrame,myFile);

            continue;

        }

    }

}

function PlaceIntoFrame(myFrame, myFile)

{

    myFrame.parent.place(myFile);

}

It works fine.

Regards,

Sathya Rani M

2 replies

Community Expert
October 12, 2013

@Sathya – you wrote:

I do not want to place the image in anchor frame

What do you exactly want then?


Placing the image at the found text position independent of the text frame? Just above the text having set the stacking order from background to foreground: 1. text frame, 2. image? Maybe obscuring the text?

Then I would add a tiny rectangle to the found text insertion point, reading out its position, remove the rectangle and move the placed image to the recorded position.

In regular text frames (not rotated ones) you could also read out the properties "horizontalOffset", "baseline" and "baselineShift" to calculate the x/y coordinates for the image to be placed.

For getting the right page to place the image you could use the "parentTextFrames[0].parentPage" of the found insertionPoint.

Uwe

Correct answer
October 18, 2013

Thank you for the reply. I have placed the image to the found textframe parent.

Please see the piece of code below.

for(k = 0; k < myTagnames.length; k++)

{

    app.findTextPreferences = null;

    app.findTextPreferences.findWhat = myTagnames;

    myFoundItems = app.activeDocument.findText();

    for (var i = 0; i < myFoundItems.length; i++)

    {

        progress.value = i+1;

        var myFile = File(myFilteredimages);

        myFrame = myFoundItems.parentTextFrames[0];

        if(myFile.exists)

        {

            app.select(myFrame.parent);

            PlaceIntoFrame(myFrame,myFile);

            continue;

        }

    }

}

function PlaceIntoFrame(myFrame, myFile)

{

    myFrame.parent.place(myFile);

}

It works fine.

Regards,

Sathya Rani M

Sergey_Anosov
Participating Frequently
October 11, 2013