Copy link to clipboard
Copied
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
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
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
Thanks, this is working perfectly!
Copy link to clipboard
Copied
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
Find more inspiration, events, and resources on the new Adobe Community
Explore Now