Insert Image into Content Control

Discussion of the "Documents" module
Post Reply
damien
Posts: 1
Joined: Tue Dec 25, 2018 6:11 am

Insert Image into Content Control

Post by damien » Tue Dec 25, 2018 7:02 am

Hello Developers,

OnlyOffice is greet!

I'm making a plugin to insert images into docx, and to get what is inserted i want to user Content Control to manage these images.
But it doesn't seem work using "InsertAndReplaceContentControls" to insert image.

the code is like:

Code: Select all

var base64Image = "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEA3A............"
var _script =
`var oDocument = Api.GetDocument();
var oParagraph = Api.CreateParagraph();
var oDrawing = Api.CreateImage("${base64Image}", 4486275, 6334124);
oDocument.InsertContent([oParagraph], true);`
console.log(_script);
_script = _script.replaceAll("\r\n", "");
_script = _script.replaceAll("\n", "");
var _scriptObject = {
	"Props": {
		"Tag": Tag,
		"Lock": 0,
		"InternalId": InternalId
	},
	"Script": _script
};
window.Asc.plugin.executeMethod("InsertAndReplaceContentControls", [[ _scriptObject ]]);

I can add a content control and focus in it by mouse, then use "InsertAndReplaceContentControls" to add an image into it, but that requires manual operation.
I've checked the plugin examples but couldn't find an example of inserting images into content control.
I wonder how to do this.
It will also help to have a certain method to focus in a content control.

environment:
win10 professional
nodejsexample
document server(docker) on centos7 on vm

thx,

Damien

Kate
Posts: 246
Joined: Mon Feb 09, 2015 11:17 am

Re: Insert Image into Content Control

Post by Kate » Wed Dec 26, 2018 11:18 am

Hello Damien,

Please, post this on developers forum which is dev.onlyoffice.org

Post Reply