I’m having trouble sending an image to the document with the postmessage API, I created a customizable button to do this, and I’m getting the document’s returns, when the button is selected I send the image to the document, but the image is not inserted, Note: I’m using iframe
receiveMessage(event) {
let jsonData = ‘’;
if(typeof event.data === ‘object’) {
jsonData = event.data;
}
else {
jsonData = JSON.parse(event.data);
}
console.log("Message received from the child: ", jsonData); // Message received from child
const protocol = window.location.protocol;
const host = window.location.host;
const port = window.location.port ? :${window.location.port}
: ‘’;
// Formar a URL base
const baseUrl = `${protocol}//${host}`;
if(jsonData.MessageId == "Clicked_Button") {
if(jsonData.Values.Id == "brasao__") {
document.getElementById('edicaoTextoDescricao').contentWindow.postMessage(
JSON.stringify({'MessageId': 'Send_UNO_Command',
'Values': {
'Command': '.uno:DefaultFormat',
'Args': {}
}
}), '*');
document.getElementById('edicaoTextoDescricao').contentWindow.postMessage(
JSON.stringify({
MessageId: 'Send_UNO_Command',
'Values': {
'Command': '.uno:InsertHeader',
'Args': {}
}
}), '*');
document.getElementById('edicaoTextoDescricao').contentWindow.postMessage(
JSON.stringify({'MessageId': 'Send_UNO_Command',
'Values': {
'Command': '.uno:CenterPara',
'Args': {}
}
}), '*');
var urlImg = baseUrl + '/ui/img/brasao.png';
urlImg = urlImg.toString();
document.getElementById('edicaoTextoDescricao').contentWindow.postMessage(
JSON.stringify({
MessageId: "Action_InsertGraphics",
Values: {
url: urlImg,
}
}), '*');
setTimeout(function() {
document.getElementById('edicaoTextoDescricao').contentWindow.postMessage(
JSON.stringify({'MessageId': 'Send_UNO_Command',
'Values': {
'Command': '.uno:InsertText',
'Args': {
Text: {
type: 'string',
value: 'PODER JUDICIÁRIO\r\n'
+' Tribunal de Justiça do Estado de Goiás\r\n'
+' Gabinete da Presidência\r\n'
},
ParaStyleName: {
type: 'string',
value: 'Heading 1' // Estilo de cabeçalho pré-definido
}
}
}
}), '*');
}, 1000);
}
if(jsonData.Values.Id == "abrir__") {
if(document.getElementById("formFile") != null && document.getElementById("formFile") != undefined) {
document.getElementById("formFile").click();
}
}
}
if(jsonData.Values!= undefined && jsonData.Values.Status == "Document_Loaded" && document.getElementById('edicaoTextoDescricao') != null && document.getElementById('edicaoTextoDescricao') != undefined) {
document.getElementById('edicaoTextoDescricao').contentWindow.postMessage(JSON.stringify({
"MessageId" : "Insert_Button",
"Values" : {
"id" : "abrir__",
"imgurl" : baseUrl + "/ui/img/folder.svg",
"hint" : "Abrir",
"insertBefore" : 'save',
"label" : "Abrir"
}
}), '*');
document.getElementById('edicaoTextoDescricao').contentWindow.postMessage(JSON.stringify({
"MessageId" : "Insert_Button",
"Values" : {
"id" : "brasao__",
"imgurl" : baseUrl + "/ui/img/brasao.png",
"hint" : "Adicionar Brasão",
"insertBefore" : 'save',
"label" : "Brasão"
}
}), '*');
}
}