Quitter
  • Communauté internationale
    • Langue:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티

Place image into text frame

Invité
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

SUJETS
Scripting
891
Traduire
Signaler
Directives de la communauté
Restez bienveillant et courtois, ne vous attribuez pas la paternité des créations d’autrui et assurez-vous de l’absence de doublons avant de poster du contenu. En savoir plus
community guidelines

correct answers 1 bonne réponse

Engagé , 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

Traduire
Débutant dans la communauté ,
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.

Traduire
Signaler
Directives de la communauté
Restez bienveillant et courtois, ne vous attribuez pas la paternité des créations d’autrui et assurez-vous de l’absence de doublons avant de poster du contenu. En savoir plus
community guidelines
Invité
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

Traduire
Signaler
Directives de la communauté
Restez bienveillant et courtois, ne vous attribuez pas la paternité des créations d’autrui et assurez-vous de l’absence de doublons avant de poster du contenu. En savoir plus
community guidelines
Engagé ,
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

Traduire
Signaler
Directives de la communauté
Restez bienveillant et courtois, ne vous attribuez pas la paternité des créations d’autrui et assurez-vous de l’absence de doublons avant de poster du contenu. En savoir plus
community guidelines
Invité
Sep 03, 2010 Sep 03, 2010
LA PLUS RÉCENTE

Thanks, this is working perfectly!

Traduire
Signaler
Directives de la communauté
Restez bienveillant et courtois, ne vous attribuez pas la paternité des créations d’autrui et assurez-vous de l’absence de doublons avant de poster du contenu. En savoir plus
community guidelines
Invité
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

Traduire
Signaler
Directives de la communauté
Restez bienveillant et courtois, ne vous attribuez pas la paternité des créations d’autrui et assurez-vous de l’absence de doublons avant de poster du contenu. En savoir plus
community guidelines