Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Place image into text frame

Guest
Sep 02, 2010 Sep 02, 2010

Hello,

I'd like to place an image into a textframe with existing text.

However, I get the error that "contents" is not defined.

textframe.contents = "testtesttest";
var file = new File('~/Desktop/ean.tif')
textframe.place(file, false);

What am I doing wrong?

Regards,

mannyk

TOPICS
Scripting
890
Translate
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 1 Correct answer

Engaged , Sep 03, 2010 Sep 03, 2010

If you want place your image to last of your textframe content then use insertionPoints[-1].

See in below code.

textframe.contents = "testtesttest";
var file = new File('~/Desktop/aa.pdf')
textframe.insertionPoints[-1].place(file, false);

Shonky

Translate
Community Beginner ,
Sep 02, 2010 Sep 02, 2010

Are you sure you are referencing the textframe properly. Can you show your code of how you initialised textframe.

I just tried:

app.activeDocument.textFrames[0].contents = "testtesttest";

It works.

Translate
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
Guest
Sep 02, 2010 Sep 02, 2010

Hello,

I have never had problems as long as I have worked with text only. So I assume that the referencing should be ok.

I now packed the processing in a function.

Now, I don't get any error message and the image is also shown. But the prior text gets replaced by the image.

My code is the following:

if (type == "paragraphArticle") {
    if (columnArticle == null) {
        columnArticle = page.textFrames.add();
        columnArticle.geometricBounds = [0, 165, 200, 195];
    }
    RenderFields(columnArticle, title, linebreak, value, isImage);
}


function RenderFields(textFrame, title, linebreak, value, isImage) {
    if (title.length > 0) {
        var titleStartIndex = textFrame.contents.length;
        textFrame.contents += title + ": ";
        textFrame.parentStory.characters.itemByRange(titleStartIndex, titleStartIndex + title.length).fontStyle = "Bold";
    }
    if (linebreak.toString().toLowerCase() == "true") {
        textFrame.contents += "\r";
    }
    if (isImage.toString().toLowerCase() == "true") {
        var t = new File('~/Desktop/ean.tif')
        textFrame.place(t, false);
    }
    else if (value.length > 0) {
        textFrame.contents += value + "\r";
    }
}

Note: The function is called several times, so the might be already text content (or images) in the text frame.

Thanks for your help!

Yours,

mannyk

Translate
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
Engaged ,
Sep 03, 2010 Sep 03, 2010

If you want place your image to last of your textframe content then use insertionPoints[-1].

See in below code.

textframe.contents = "testtesttest";
var file = new File('~/Desktop/aa.pdf')
textframe.insertionPoints[-1].place(file, false);

Shonky

Translate
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
Guest
Sep 03, 2010 Sep 03, 2010
LATEST

Thanks, this is working perfectly!

Translate
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
Guest
Sep 03, 2010 Sep 03, 2010

I have found out that if you select the whole textframe with the cursor and then manually click on "place" to choose an image the existing text gets also replaced. Only when you are at textmode (double click into the textframe) the image gets appended.

Maybe this has to be simulated also in the script to get it working?

Regards,

mannyk

Translate
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