Atti
Atti

Reputation: 160

insertInlinePictureFromBase64 is undefined in Word2016

I'm trying to insert an image into a word document using the following method: bodyObject.insertInlinePictureFromBase64, but I get the error that the method is not defined. However the rest of the methods enumerated here seem to be available, only this one is missing. I'm looking for some clearance if this one is truly not available yet? If it is true that it isn't available at the moment, will it then be available in the near future?

Upvotes: 2

Views: 1221

Answers (2)

Juan Balmori
Juan Balmori

Reputation: 5046

...also i just noted that you said you want to insert an image. the insertFileFromBase64 method is designed to insert whole Word documents. (i.e. a docx file) if you want to insert an image you need to use the Body.insertInlinePictureFromBase64(base64EncodedImage, insertLocation) method. go here for reference which is also part of the 1.2 requirement set.

Upvotes: 1

Juan Balmori
Juan Balmori

Reputation: 5046

This is an excellent question Oskar thanks for asking. The reason why I am pretty sure you are seeing this issue is because in the Word build you are using the Word 1.2 Requirement set may not be supported and you need to update Word. In order to check this please go to File-> Account and make sure your build is 6568+ (check image below). if you don't have 6568.xxxx+ sure to update your Office.

enter image description here

Now, to safely use this method you want to make sure, at runtime, if the host that is executing your add-in actually supports the 1.2 requirement set, and its simple to check via "isSetSupported" method. see this example:

 if (Office.context.requirements.isSetSupported("WordApi", "1.2")) {
         Word.run(function (context){
        var myBase64File = getDocumentAsBase64(); // assumes gets a docx file as base64
        context.document.body.insertFileFromBase64(myBase64File, "end");
        return context.sync();
    })
          .catch(function (myError) {
              //otherwise we handle the exception here!
              app.showNotification("Error", myError.message);
          })        }
    else {
        //if you reach this code it means that the Word executing this code does not yet support the 1.2 requirement set. in this case you can also insert a paragraph and then insert the document on the paragraph.

        app.showNotification("Error. This functionality requires Word with at least January update!! (check  builds 6568+)");   

    }

Finally to check what APIs are supported on each requirements set, please see this page

I hope you find this post very helpful.

Upvotes: 2

Related Questions